-->
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.  [ 5 posts ] 
Author Message
 Post subject: Not sure on how to map two tables.
PostPosted: Mon Mar 19, 2007 7:47 pm 
Newbie

Joined: Mon Mar 19, 2007 6:15 pm
Posts: 19
Location: Bilbao (Spain)
Hi everyone, this is my first post and it's for a question :( . I'm a hibernate newbie and I've been following the "Begining Hibernate - From Novice to Professional" book. I've been searching through the forums and google, but I'm unable to see a clear way of mapping the relationship between the users table and the messages table.

I've created both POJOS for the users and messages table.

My Hibernate version is 3.2

Link to Database E-R image


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 2:58 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi Cybrid,

From Er digram i could see that message have one from(user) and one TO (user)

For that use in message HBM many to one for from and to.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 4:42 am 
Newbie

Joined: Mon Mar 19, 2007 6:15 pm
Posts: 19
Location: Bilbao (Spain)
Hi Dharmendra, thank you very much for your fast response; but another question arises to me; is it possible to use Collections for a many-to-one relationship?, I mean, the book I mentioned states that collections should only be used in many-to-many relationships.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 4:56 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi Cybrid,

have a reference



http://www.hibernate.org/hib_docs/v3/re ... tions.html

http://www.java2s.com/Code/Java/Hiberna ... deSave.htm

http://vetula.com/blog/archives/2004/08 ... hibernate/

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 6:06 am 
Newbie

Joined: Mon Mar 19, 2007 6:15 pm
Posts: 19
Location: Bilbao (Spain)
God, I'm getting a headache; since users table is the "one" side of the relationship, shouldn't a one-to-many relationship in the Users hbm be putted?, instead of a many-to-one in the messages ("many" side) in the messages hbm?.

In my object's model, the user pojo contains a set of sent messages and another for received messages, or am I getting the wrong aproach?.

Thanks again for your time :D .


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