逆向工程检查约束条件和带 Hibernate 的索引?
我的任务是从大型遗留 SQL Server 数据库中对 Hibernate 映射进行逆向工程。数据库广泛使用检查约束(每个表几个)和索引,虽然我认为这些是 DBA 关心的问题,但我们需要将它们保留在 Hibernate 映射中。
使用 Hibernate Tools for Eclipse,我可以成功将表逆向工程为 .hbm.xml 文件;但是,不存在任何检查约束或索引。我知道可以手动将检查约束和索引直接添加到映射中,例如:
<class name="package.Tablename"
table="TABLENAME"
schema="dbo"
catalog="MyDB"
check="START_DATE < END_DATE"> <!-- here -->
...
<property name="endDate" type="timestamp" index="IDX_END_DATE"> <!-- here -->
<column name="END_DATE" />
</property>
...
</class>
我们有数百个表和数千个索引/检查约束,因此手动将它们添加到反向工程映射中实际上并不可行。
是否有可能让 Hibernate Tools 为我们输出这些内容?如果是这样,怎么办?如果没有,有人可以推荐另一个可以做到这一点的工具吗?
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 < 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Hibernate Tools 无法开箱即用地执行此操作;但是,可以将 DDL 添加到
元素。为了对这些信息进行逆向工程,您必须编写一个 自定义实用程序通过自定义模板调用的类一个>。由于大量
无法提供我的雇主想要的抽象级别和一般用户友好性,因此我们选择不采用这种方法,并以不同的方式对我们的数据库进行建模。方式。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.