-->
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.  [ 3 posts ] 
Author Message
 Post subject: two one to many associations that point to the same object
PostPosted: Tue Dec 15, 2009 10:20 pm 
Beginner
Beginner

Joined: Wed Mar 19, 2008 12:10 am
Posts: 36
i'm using hibernate as my JPA layer. I want to be able to do:

user.getSentMessages()
and
user.getReceivedMessages()

where both of those would be hitting the Messages object.

The messages object would have sender and receiver properties. Is it possible/advisable to map an association like this? How would you do it using JPA annotations?


Last edited by ew0kian on Tue Dec 15, 2009 10:58 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: two one to many associations that point to the same object (
PostPosted: Tue Dec 15, 2009 10:57 pm 
Beginner
Beginner

Joined: Mon Dec 14, 2009 12:26 am
Posts: 23
Sure. It's just a table with two foreign-key references to the same primary key in some other table. So just map it using @OneToMany on each referencing column. Hibernate doesn't care that the two @OneToMany mappings point to the same target entity.


Top
 Profile  
 
 Post subject: Re: two one to many associations that point to the same object
PostPosted: Tue Dec 15, 2009 11:03 pm 
Beginner
Beginner

Joined: Wed Mar 19, 2008 12:10 am
Posts: 36
cool. thanks for clearing this up. its one of those things where i looked in the book and didnt see anything about it so i assumed it might not be possible


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