Skip to main content

Custom schema generation with Hibernate annotations

Posted by johnsmart on August 5, 2008 at 3:10 PM PDT

Hibernate 3 annotations are a great way to persist your domain model in a database backend. It's quite easy to have Hibernate generate or update the database schema as required, and not have to hand-code SQL scripts at all. However, this approach often hits a few hurdles when it reaches the DBA teams - they usually insist on obscure and archaic naming conventions, and sometimes even want to see the SQL script before modifying the producton database!

Luckly, you don't have to go back to the bad old ways of hand-coded SQL and convoluted XML mappings just yet - Hibernate annotations can cope with all this. For those interested, I've written up some details on how to do, including a few pit-traps to avoid, in new article on Javaworld.

Comments

John, Great post. I just came across it (I'm a little slow I guess). Do you have any recommendations on how to customize the naming strategy for constraints as well? We are trying to enforce Primary Key: table_name_pk Unique Constraint: table_name_ux1, table_name_ux2, etc I can't find any easy way to override that strategy. Thanks! Leo