【发布时间】:2015-02-11 18:58:23
【问题描述】:
我正在尝试使用 DelegatingReverseEngineeringStrategy 生成 pojos 和 hbm 文件。我能够自定义诸如实现接口、toString 方法、急切获取所有表对象之类的东西。
不过,我还需要自定义两个功能:
考虑两个表 Parent 和 Child,其中 Parent 和 Child 之间存在一对多关系。
我想:
为父 hbm 中的子集合设置 inverse="false"
-
在父 hbm 中为子集合设置 cascade="all",这样如果我更新父集合,它应该将效果级联到子集合。
<hibernate-mapping> <class name="com.xyz.Parent" table="PARENT" schema="FAMILY"> <meta attribute="implements" inherit="false">SomeInterface</meta> <meta attribute="extra-import" inherit="false">com.xyz.SomeInterface</meta> <property name="parentColumn" type="date"> <meta attribute="use-in-tostring" inherit="false">true</meta> <column name="PARENT_COLUMN" length="7" /> </property> <set name="child" table="Child" **inverse="false"** lazy="false" fetch="select" **cascade="all"**> <key> .... </key> <one-to-many class="com.xyz.Child" /> </set> </class> </hibernate-mapping> -
在 Child 的 hbm 中将 Parent 作为外键排除 - 以避免在代码中反向查找。
<hibernate-mapping> <class name="com.xyz.Child" table="CHILD" schema="FAMILY"> <meta attribute="implements" inherit="false">SomeInterface</meta> <meta attribute="extra-import" inherit="false">com.xyz.SomeInterface</meta> <property name="childColumn" type="date"> <meta attribute="use-in-tostring" inherit="false">true</meta> <column name="CHILD_COLUMN" length="7" /> </property> </composite-id> **-- I do not want this in CHILD <many-to-one name="parent" class="com.xyz.Parent" update="false" insert="false" fetch="select"> <meta attribute="use-in-tostring" inherit="false">true</meta> .... </many-to-one>** </class> </hibernate-mapping>
有没有办法在 DelegatingReverseEngineeringStrategy 中找到关联信息?一些可以为每个表提供一对多、一对一等信息的类。
【问题讨论】:
标签: hibernate reverse-engineering hibernate-tools hbm