-->
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.  [ 8 posts ] 
Author Message
 Post subject: two child lists of the same type
PostPosted: Mon Oct 29, 2007 3:07 am 
Beginner
Beginner

Joined: Mon Sep 03, 2007 4:25 pm
Posts: 24
I have one parent class which must keep two child lists, both are of the same class.

// parent
public class CustomTable
{
private List<FieldStatement> fieldStatements;
private List<FieldStatement> gridButtonStatements;
}

CustomTable.hbm.xml:

<list name="fieldStatements" cascade="all-delete-orphan">
<key column="CUSTOMTABLEID" not-null="true"/>
<list-index column="statementIdx"/>
<one-to-many class="com.jcalc.core.page.FieldStatement"/>
</list>

<list name="gridButtonStatements" cascade="all-delete-orphan">
<key column="CUSTOMTABLEID" not-null="true"/>
<list-index column="gridButtonIdx"/>
<one-to-many class="com.jcalc.core.page.FieldStatement"/>
</list>

// child
public class FieldStatement extends Entity
{
private CustomTable customTable;
}

FieldStatement.hbm.xml:
<many-to-one name="customTable"
class="com.jcalc.core.page.CustomTable"
column="CUSTOMTABLEID"
not-null="true"
insert="false"
update="false"/>

these configuration files worked when I had just one child list. after adding the second list, I get a
Repeated column in mapping for entity: FieldStatement column: CUSTOMTABLEID
(should be mapped with insert="false" update="false")

I am sure, hibernate is able to treat such a design. But how to make it accept the .hbm?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 29, 2007 7:21 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
Error message say it itself

"Repeated column in mapping for entity: FieldStatement column: CUSTOMTABLEID
(should be mapped with insert="false" update="false")
"

You need to map second collection as readonly (through insert and update attributes).

_________________
Please rate this post if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 29, 2007 2:17 pm 
Beginner
Beginner

Joined: Mon Sep 03, 2007 4:25 pm
Posts: 24
CUSTOMID is already set for insert=false and update=false.

<quote>
map second collection as readonly
</quote>

why is that a solution? crippling the second list?
the second list is just as dynamic as the first. there is no difference in the way I want to use the second list from how I use the first list. you mean hibernate can not support a feature that is so natural in straight java programming using jdbc?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 31, 2007 5:08 pm 
Beginner
Beginner

Joined: Mon Sep 03, 2007 4:25 pm
Posts: 24
I am sure somebody has done this before. it's a very realistic design.

some body help out please!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 02, 2007 1:16 pm 
Newbie

Joined: Wed Oct 17, 2007 2:20 pm
Posts: 3
I just glanced at this thread, but if it was me, I would change the one-to-many to a many-to-many and map both associations with join tables. You're using a one-to-many, which means your FieldStatement has a single foreign-key pointing back to the parent, and with two associations, it probably can't figure it out.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 02, 2007 2:10 pm 
Beginner
Beginner

Joined: Mon Sep 03, 2007 4:25 pm
Posts: 24
that would be very disappointing, if what you say is true.

seems to me, all you have to do is assign different index column names to the two lists, then there is no conflict at all between the two lists. therefore, I would think hibernate can handles this. if I just get a reply on how.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 02, 2007 9:18 pm 
Newbie

Joined: Tue Sep 04, 2007 2:21 pm
Posts: 14
Since you are using the same column as a FK into the customTable Hibernate doesn't understand how to differentiate between the two lists.

Maybe what you have is two different subtypes in the customTable? - could manage them in the same collection?

How do you differentiate the instances loaded in the two collections you have defined now?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 03, 2007 12:38 pm 
Beginner
Beginner

Joined: Mon Sep 03, 2007 4:25 pm
Posts: 24
there is no conflict in having two lists with the exact same type.

in the database, each type will have a different list index column filled (statementIdx vs. .gridButtonIdx). I hope you know what that means. and hibernate can work out which row belongs to which list, even if both types of rows have the same FK.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.