-->
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: Many to two relationship?
PostPosted: Sun Jul 18, 2010 10:34 am 
Newbie

Joined: Sun Jul 18, 2010 10:15 am
Posts: 8
I'm sorry for the dumb title, but I'm just starting to tinker with hibernate (loving it btw) and i'm finding that the way I'd normally design my objects presents an issue.

to abridge my application:
I have an Account class with a set of Transfers
Set<Transfer>
my Transfer class has two instances of Account
Account source;
Account destination;

I've learned by trying that I can't have two many-to-one relationships in the Transfer class, which makes sense I just thought it was worth a try...I'd prefer not to have a set of Accounts in the Transfer class. From doing lots of searching I think a solution would be to add two classes, TransferSource and TransferDestination. so now

Account:
TransferSource sourceTransfers;
TransferDestination destTransfers;
TransferSource:
Set<Transfer> transfersFrom;
TransferDestination:
Set<Transfer> transfersTo;
Transfer:
TransferSource source;
TransferDestination dest;

But now I have a one-to-one between Account and each of TransferSource and TransferDestination with a one-to-many between each of those to Transfer. This seems convoluted to me even though I'm pretty sure it will work. My guess is that this is a pretty common pattern, problem and I have just failed to find the right info. could any one please make a suggestion or comment?

it is much appreciated.


Top
 Profile  
 
 Post subject: Re: Many to two relationship?
PostPosted: Sun Jul 18, 2010 11:34 pm 
Newbie

Joined: Sun Jul 18, 2010 10:15 am
Posts: 8
figured this out, and for any other hibernate newbie who may run across a similar problem, I used two one-to-many/many-to-one Bidirectional associations with join tables. it works like a charm and I did not have to add two more classes (TransferSource and TransferDestination)


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.