-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to map 2 one-to-many relationships against same table?
PostPosted: Tue Mar 08, 2011 4:06 pm 
Newbie

Joined: Tue Mar 08, 2011 3:55 pm
Posts: 6
I have a relationship like the following:

create TABLE PARENT (
parent_id int PK,
some_value varchar
)

create TABLE CHILD (
child_id int PK,
parent_id int FK,
type char(1),
some_other_value varchar
)

However, the object looks like:

public class Parent {
private int id;
private String someValue;
private List<Child> typeAChilden;
private List<Child> typeBChilden;
}

public class Child {
private int id;
private String someOtherValue;
}

The type column in the CHILD table would be of either value "A" or "B" which would determine what list it would be loaded/inserted/updated from. It should also be noted that each row in CHILD has a unique id.

Im trying to work out how to implement this in xml mappings. I was thinking to use the where clause in the one to many definition but it wonty allow this.

Any ideas on this would be very helpful.


Top
 Profile  
 
 Post subject: Re: How to map 2 one-to-many relationships against same table?
PostPosted: Thu Mar 10, 2011 6:15 am 
Newbie

Joined: Tue Mar 08, 2011 3:55 pm
Posts: 6
Any advice on this one? Its causing me a bit of issue.

thanks


Top
 Profile  
 
 Post subject: Re: How to map 2 one-to-many relationships against same table?
PostPosted: Thu Mar 10, 2011 6:47 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
I'd prefer to map two foreign keys in the child table so you do not need the type-column anymore.

The where-clause should work also, btw.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: How to map 2 one-to-many relationships against same table?
PostPosted: Thu Mar 10, 2011 4:51 pm 
Newbie

Joined: Tue Mar 08, 2011 3:55 pm
Posts: 6
Thanks for the response.

Unfortunately I don't have control over the database schema.

I tried using the where clause but it didn't seem to like it when I mapped 2 different variables (each with different types) to the same object type.


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