views:

184

answers:

2

I already have hibernate mapping files and pojos created by Netbeans to which I've added named queries and extra methods.

Now I've added another table to the database and a foreign key column to an existing table.

It's not a big problem with just one table to add the mappings by hand but it gets tedious and error prone with more.

What I do at the moment is use a wizard to create a whole new set of classes and mappings in a new package and manually merge them, which in itself is prone to mistakes.

Is there a way to automagically update the .hbm and java files?

+3  A: 

What you are trying to acheive is not the best way of keeping the database and hibernate in sync. If possible, you should do the other way around - make changes in the hibernate mappings, and let them be reflected in the database.

After all, it's your object model that matters, not the database representation.

Check the hibernate.hbm2ddl.auto property here. If set to update, it will update the underlying database with the appropriate columns and constraints based on the changes in your hibernate mappings.

Bozho
+2  A: 

NetBeans has Reverse Engineering support since 6.5 but it doesn't seem to offers round-trip. So, sadly, I think that you'll have to stick with your current approach.

Pascal Thivent