Java – can I automatically update hibernate POJOs and mappings in NetBeans after adding a new table?

I already have hibernate mapping files and POJOs created by NetBeans, and I have added named queries and additional methods

Now I have added another table to the database and a foreign key column to the existing table

Only one table can be mapped manually, which is not a big problem, but it becomes tedious and error prone

What I do now is to use the wizard to create a new set of classes and mappings in the new package and merge them manually, which is error prone in itself

Is there any way to update automatically HBM and java files?

Solution

What you want to achieve is not the best way to keep the database synchronized with hibernation If possible, you should do the opposite - make changes in the hibernate map and have them reflected in the database

After all, what matters is your object model, not the database representation

Check hibernate hbm2ddl. Auto attribute here If set to update, it will update the underlying database with appropriate columns and constraints according to the changes in the hibernate map

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>