Reputation: 56
I am trying to generate the pojos and hbm files using DelegatingReverseEngineeringStrategy. I am able to customize things like implementing interface, toString method, eager fetch for all table objects.
However, I need to customize two more features:
Consider two table Parent and Child where there is one to many relationship between Parent and Child.
I would like to:
set inverse="false" for Child collection in Parent hbm
set cascade="all" for Child collection in parent hbm so that if I update Parent collection it should cascade the effect to child collection.
<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>
exclude Parent as foreign key in Child's hbm - to avoid reverse look up in the code.
<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>
Is there a way to find out the association info in DelegatingReverseEngineeringStrategy? Some Class that can give one-to-many, one-to-one etc. information for each Table.
Upvotes: 1
Views: 959
Reputation: 51
Appears that it should be possible by overriding DelegatingReverseEngineeringStrategy.foreignKeyToAssociationInfo(ForeignKey) however the function doesn't seem to be called at all during the the entity creation build :(
Can just do a regex replace after the build is complete via maven. Somethign like Find
@ManyToOne\((.*)\)[\r\n\s]+@JoinColumn\((.*)\)[\r\n\s]+public Entity getEntity\(\)
Replace with
@ManyToOne($1, cascade=javax.persistence.CascadeType.ALL)\r\n\t@JoinColumn($2, updatable=false, insertable=false)\r\n\tpublic Entity getEntity()
Upvotes: 1