Monday, November 2, 2009

DDL in Hibarenate Mapping File

If you set Hibernate property "hibernate.hbm2ddl.auto" to "create", Hibernate can automatically create the schema with the mapping files. Great! But what if you have things like triggers? It turns out you can add the specific DDL to element in the mapping file for this purpose.

<hibernate-mapping>
<class>
...
</class>

<database-object>
<create>
[CREATE statement]
</create>
<drop>
[DROP statement]
</drop>
<dialect-scope name="org.hibernate.dialect.HSQLDialect" />
</database-object>
</hibernate-mapping>


The elements restrict the custom CREATE or DROP statements to
a particular set of configured database dialects, which is useful if you’re deploying
on several systems and need different customizations.

No comments:

Post a Comment