Search code examples
hibernateinitializationhbm2ddl

manual initialization of required Hibernate database tables


I'm getting started in Hibernate and so far it's not too hard. But I am confused about the hbm2ddl.auto property. Is there a way to manually execute whatever this does to initialize the database tables? I only want to do this after I make my database changes, not every time I run my program.

edit: what about at runtime? is there a way in my Java program to programmatically re-initialize the database tables? org.hibernate.tool.hbm2ddl.SchemaUpdate looks maybe like the right beast but I'm not sure what it does exactly.


Solution

  • I would use the HBM2DDL to generate the database, then use whatever replication / backup exists on your database to save your database schema, and use that scripting to recreate your database whenever you need to; only run the HBM2DDL to generate your database when your object model changes.