-->
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: many to many problem
PostPosted: Thu Nov 06, 2008 7:14 am 
Newbie

Joined: Thu Nov 06, 2008 7:11 am
Posts: 2
hey ppl, I'm new to hibernate and I'm working on this erd with many to many relatio

Table 'user':

* id: integer

username: varchar
------------------------------------------------------------------

table 'user_info':

* user_id: integer (pk,fk: ref:table 'user' column:'id')

* info_id: integer (pk,fk:ref:table 'info' column:'id')

info_value: text
------------------------------------------------------------------

table 'info':

* id: integer

info:varchar
------------------------------------------------------------------

it's simple many to many relation between user and info tables with the join table user_info that have a third column that contains a requried value holded for the intersection between user and information.

I've made a bean for that table and in the mapping for tables user and info i added the composite-element tag in the set collection and inverse attribute in each of them and now i can get the value from the join table.

until now every thing is great but first problem i have is i must use a map collection so i can get the value with it's key that will be the name of the info in the 'info' table but i couldnt put the key of the map from that table :(

second problem i got is that i can only retrieve data from that column (third column) which is a very important, actually it's the purpose of the system depends on the storing and retrieving values from this column

so please can any one help me out in this ,how to map these tables and how can i populate and retrieve values from them

or just tell me about a good book that explain like this problem in full details, I've read hibernate quickly and hibernate in action but i couldn't find a proper solution for this problem

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2008 7:10 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
decompose this many-to-many relationship into 2 one-to-many relationships: one from user to user-info, the other from info to user-info.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 09, 2008 8:57 am 
Newbie

Joined: Thu Nov 06, 2008 7:11 am
Posts: 2
gonzao_diaz wrote:
decompose this many-to-many relationship into 2 one-to-many relationships: one from user to user-info, the other from info to user-info.


much appreciated for ur reply but i tried to do it in this way using mapping but when i tried to persist an object that holds a value for user_info it failed to populate values in the db


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 09, 2008 11:43 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Then, you should address that new problem, but decomposing the relationship in 2 one-to-many is still the way to go.

A pure many-to-many table, with no additional fields,is very rare in real-life systems. Most associations will be one-to-many or one-to-one.

_________________
Gonzalo Díaz


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.