我已被任务从大型,遗留,SQL Server数据库中逆向工程休眠映射。数据库大量使用检查约束(每个表)和索引,虽然我认为这些是DBA问题,我们需要在Hibernate映射中保存它们。

使用eClipse的Hibernate工具,我可以成功地将工程师逆转到.hbm.xml文件;但是,没有检查约束或索引。我知道可以手动将两个Check约束和索引直接添加到映射,例如:

<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>
.

我们有数百个表格和数千个索引/检查约束,因此用手向反向工程映射添加不是真的可行的。

是否可以让Hibernate工具为我们吐出这些工具?如果是这样,怎么样?如果没有,任何人都可以推荐另一个会这样做的工具?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top