Question

I've been tasked with reverse engineering Hibernate mappings from a large, legacy, sql server database. The database makes extensive use of check constraints (several per table) and indexes, and while I would argue that these are DBA concerns, we're required to preserve them in the Hibernate mappings.

Using Hibernate Tools for Eclipse, I can successfully reverse engineer our tables into .hbm.xml files; however, none of the check constraints or indexes are present. I know that it's possible to manually add both check constraints and indexes directly to the mapping, e.g.:

<class name="package.Tablename" 
       table="TABLENAME" 
       schema="dbo" 
       catalog="MyDB"
       check="START_DATE &lt; END_DATE"> <!-- here -->
   ...
   <property name="endDate" type="timestamp" index="IDX_END_DATE"> <!-- here -->
            <column name="END_DATE" />
   </property>
   ...
</class>

We have hundreds of tables and thousands of indexes/check constraints, so adding these by hand to the reverse engineered mappings isn't really feasible.

Is it possible to get Hibernate Tools to spit these out for us? If so, how? If not, can anyone recommend another tool that will do this?

Was it helpful?

Solution

It's not possible to do this out of the box with Hibernate Tools; however, it is possible to add DDL to your mappings inside of <database-object> elements. In order to reverse engineer this information, you'll have to write a custom utility class that is invoked via a custom template.

Since a boatload of <database-object>s didn't provide the level of abstraction and general user-friendlyness that my employer wanted, we opted not to take this approach and modeled our database in a different manner.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top