2014-12-13 54 views
1

我想使用DelegatingReverseEngineeringStrategy生成pojos和hbm文件。我能够自定义诸如实现接口,toString方法,对所有表对象的渴望获取等。使用DelegatingReverseEngineeringStrategy休眠逆向工程

不过,我需要定制两个特点:

考虑两个表中父母与子女,其中有一个父母与子女之间的多对多关系。

我想:

  1. 组反=“假”在父HBM子集合

  2. 一套级联=“全”在父HBM子集,这样如果我更新家长收集它应该将效果级联到儿童收集。

    <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> 
    
  3. 排除Parent作为Child's 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> 
    

有没有办法找出在DelegatingReverseEngineeringStrategy协会信息?某些类可以为每个表提供一对多,一对一的信息。

回答

1

看来,它应该通过重写DelegatingReverseEngineeringStrategy.foreignKeyToAssociationInfo(ForeignKey的)是可能的但功能似乎并没有在所有被称为实体创建构建:(

可以做一个正则表达式替换后的期间打造的是通过行家完成。Somethign像 查找

@ManyToOne\((.*)\)[\r\n\s][email protected]\((.*)\)[\r\n\s]+public Entity getEntity\(\) 

@ManyToOne($1, cascade=javax.persistence.CascadeType.ALL)\r\n\[email protected]($2, updatable=false, insertable=false)\r\n\tpublic Entity getEntity() 
更换