-->
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.  [ 6 posts ] 
Author Message
 Post subject: A many to many mapping with extra columns
PostPosted: Mon Jul 16, 2007 4:38 am 
Newbie

Joined: Mon Jul 16, 2007 3:19 am
Posts: 5
hi,
I am quite new in nhibernate and have a question:
I have 3 tables:

1 - Voters (VoterId, name1, ...)
2 - Customers (customerId, name2, . . .)
3 - VoterCustomer (VoterId, customerId, name3 and additional columns)

I have been confused between : set, bag, many-to-many, ...
and I do not know how and where to define the name3 and additional columns ?
I have class Voter which has: name1, name3, and additional columns

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 4:50 am 
Beginner
Beginner

Joined: Tue Jul 10, 2007 5:27 am
Posts: 34
Location: Belgium
if you have additional columns this really isn't a typical many-to-many mapping. I'd go for a one-to-many on both sides, both referring to entities which represent the link + the additional columns

_________________
Davy Brion
http://ralinx.wordpress.com


Top
 Profile  
 
 Post subject: Additional explanation
PostPosted: Mon Jul 16, 2007 8:53 am 
Newbie

Joined: Mon Jul 16, 2007 3:19 am
Posts: 5
Thanks for your quick reply !
Actualy it's a bit more complex:

In table "Voters" I have composite PK: VoterID+CustomerID,
when this happens, the relation to "VoterCustomer" table, is 'one-to-one'.
because in "VoterCustomer" I have the same composite PK: VoterID+CustomerID.
(I have a reason why do not merge to an one table.)
So, how do I define such a mapping with two composite PK ?

Thanks a lot !


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 9:18 am 
Beginner
Beginner

Joined: Tue Jul 10, 2007 5:27 am
Posts: 34
Location: Belgium
Quote:
In table "Voters" I have composite PK: VoterID+CustomerID,
when this happens, the relation to "VoterCustomer" table, is 'one-to-one'.


what exactly do you mean with 'when this happens'? If the primary key of Voter consists of VoterID + CustomerID, and the primary key of VoterCustomer is also VoterID + CustomerID then shouldn't it always be a one-to-one relation?

_________________
Davy Brion
http://ralinx.wordpress.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 9:54 am 
Newbie

Joined: Mon Jul 16, 2007 3:19 am
Posts: 5
You are right in principle, but I want to say something like that:

In "Voters" table:
if customerId = 0, then this voter has no appropriate voterCustomer row,
else,
the VoterId+CustomerId will be the PK in VoterCustomer.
How can I define a mapping like that?

I tried to define :
<one-to-one name="voterCustomer" class="LocalDll.VoterCustomer" outer-join="auto" property-ref="order"/>
what's the meaning of the attribute: property-ref ?
and if I have composite PK, how to define it ?

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 11:49 am 
Beginner
Beginner

Joined: Tue Jul 10, 2007 5:27 am
Posts: 34
Location: Belgium
i don't know if you can define a mapping like that... i still don't understand why you'd want to do it this way

_________________
Davy Brion
http://ralinx.wordpress.com


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