-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Child collections management by multiple parent entities
PostPosted: Wed Sep 16, 2009 12:01 pm 
Newbie

Joined: Wed Sep 16, 2009 11:42 am
Posts: 1
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?


Top
 Profile  
 
 Post subject: Re: Child collections management by multiple parent entities
PostPosted: Wed Sep 16, 2009 12:13 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi midtown_hibernate,

this looks like bad programming style to me (or you're leaving something out).

Why don't you have a common super class for your two parent entities and let the child reference that super class?

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.