使用DelegatingReverseengEngineeringStrategy的Hibernate逆向工程

使用DelegatingReverseengEngineeringStrategy的Hibernate逆向工程,hibernate,reverse-engineering,hibernate-tools,hbm,Hibernate,Reverse Engineering,Hibernate Tools,Hbm,我正在尝试使用DelegatingReverseengEngineeringStrategy生成POJO和hbm文件。我能够定制一些东西,比如实现接口、toString方法、所有表对象的即时获取 但是,我还需要定制另外两个功能: 考虑两个表父表和子表,其中父表和子表之间存在一对多关系 我想: 为父hbm中的子集合设置inverse=“false” 在父hbm中为子集合设置cascade=“all”,这样,如果我更新父集合,它应该将效果级联到子集合 <hibernate-mapping>

我正在尝试使用DelegatingReverseengEngineeringStrategy生成POJO和hbm文件。我能够定制一些东西,比如实现接口、toString方法、所有表对象的即时获取

但是,我还需要定制另外两个功能:

考虑两个表父表和子表,其中父表和子表之间存在一对多关系

我想:

  • 为父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>
    
    
    SomeInterface
    com.xyz.SomeInterface
    真的
    ....
    
  • 排除父项作为子项hbm中的外键-以避免代码中的反向查找

    <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>
    
    
    SomeInterface
    com.xyz.SomeInterface
    真的
    **--我不想让这个在孩子身上
    真的
    ....
    **
    

  • 在DelegatingReverseengEngineeringStrategy中有没有找到关联信息的方法?某些类可以为每个表提供一对多、一对一等信息

    似乎可以通过覆盖DelegatingReverseengEngineeringStrategy.ForeignKey到AssociationInfo(ForeignKey)来实现,但是在实体创建构建期间似乎根本没有调用该函数:(

    可以在构建完成后通过maven.something进行正则表达式替换 发现

    取代

    @ManyToOne($1, cascade=javax.persistence.CascadeType.ALL)\r\n\t@JoinColumn($2, updatable=false, insertable=false)\r\n\tpublic Entity getEntity()
    
    @ManyToOne($1, cascade=javax.persistence.CascadeType.ALL)\r\n\t@JoinColumn($2, updatable=false, insertable=false)\r\n\tpublic Entity getEntity()