Having problems with a one-to-any relationship where the "foreign key column" is the same as my id column.
After some refactoring the stuff I asked about in
this post, Hibernate is choking on duplicate columns inside my <any> mapping, and it doesn't seem like there is a way to configure those column mappings so that
insert="false" update="false"
Here is the mapping:
Code:
<class name="com.orixcm.prism.business.TPPropertyReport" table="third_party_property_report" >
<id name="id" type="long" unsaved-value="null" >
<column name="third_party_property_report_id" sql-type="int" not-null="true"/>
<generator class="identity"/>
</id>
<property name="vendorName" column="vendor_name" />
<many-to-one name="type" column="third_party_property_report_type_id"/>
<any name="reportDetail" id-type="long" meta-type="com.orixcm.prism.business.CustomTypeMapper" >
<column name="third_party_property_report_type_id" />
<column name="third_party_property_report_id"/>
</any>
...
One of my <any> classes:
Code:
<class name="com.orixcm.prism.business.Appraisal" table="appraisal">
<id name="id" type="long" unsaved-value="null" >
<column name="third_party_property_report_id" sql-type="int" not-null="true"/>
<generator class="foreign">
<param name="property">report</param>
</generator>
</id>
<property name="valuationAmount" column="valuation_amount"></property>
...
So, Hibernate sees:
Code:
<many-to-one name="type" column="third_party_property_report_type_id"/>
and then it gets to my <any> mapping and sees
Code:
<column name="third_party_property_report_type_id" />
And Hibernate decides that one of those column mappings MUST disallow updates, so it stops and tells me so.
The problem is that the only place to disallow updates is on the "type" property mapping, which is exactly where I need to be able to do updates. It's the <any> mapping that I want to set that column to
insert="false" update="false".
Also, the same thing happens for my second column mapping in the <any>, because it is the same column that is used as the id for my persistent class (because it is a one-to-one relationship with the <any> class):
Code:
<column name="third_party_property_report_id"/>
Clearly, I can't and wouldn't want to declare my <id> to be insert="false" update="false".
So I'm pretty stuck.
Any ideas / workarounds anyone?