I have a dependent entity named ChildEntity with two parents ParentEntity1 and ParentEntity2. So,the structure something like this
Code:
ParentEntity1{
List<ChildEntity> children;
}
ParentEntity2{
List<ChildEntity> children;
}
ChildEntity{
int sortOrder;
// back pointer
ParentEntity1 parent1;
ParentEntity2 parent2;
}
The mapping works good with
child collection as part of only one parent but when I change it for both parents to have this collection it is breaking.. I mean in the above classes, the 'children' collection can be only at either ParentEntity1 or ParentEntity2 then it works otherwise it breaks.
Some details about mapping:
ChildEntity.hbm.xml
Code:
<many-to-one name="parentEntity1" class="ParentEntity1" insert="false" update="false" column="PARENT1_COLUMN" />
<many-to-one name="parentEntity2" class="ParentEntity2" insert="false" update="false" column="PARENT2_COLUMN" />
[i]<property name="sortOrder" column="SORT_ORDER" type="integer" insert="false" update="false"></property>[/i]
ParentEntity1.hbm.xml
Code:
<list name="children" table="CHILD" cascade="all-delete-orphan" batch-size="20">
<key column="PARENT1_COLUMN" not-null="true"></key>
<list-index column="SORT_ORDER"/>
<one-to-many class="ChildEntity"></one-to-many>
</list>
and ParentEntity2.hbm.xml
Code:
<list name="children" table="CHILD" cascade="all-delete-orphan" batch-size="20">
<key column="PARENT2_COLUMN" not-null="true"></key>
<list-index column="SORT_ORDER"/>
<one-to-many class="ChildEntity"></one-to-many>
</list>
When I run this it is giving an error, which is a bit misleading:
Code:
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.hbo.it.go.profile.tray.model.TrayItem column: SORT_ORDER (should be mapped with insert="false" update="false")
Any thoughts?