javahibernateormtop-down

Is there a simple workflow to generate a database schema from classes with hibernate mappings?


Id like to define my objects then use hibernate to generate my ddl from this. But it seems like the only real workflow with hibernate is to generate a datbase schema and then reverse engineer it. Am I wanting to do something that makes no sense?


Solution

  • Yes there is a property hibernate.hbm2ddl.auto. The documentation says:

    Automatically validates or exports schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly.

    e.g. validate | update | create | create-drop

    There are multiple ways to define this property, depending on how you configure your SessionFactory. The hibernate way is to simply add:

    <property name="hibernate.hbm2ddl.auto">update</property>