-->
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: Hibernate beginner, confusion w/ one-to-one and many-to-one
PostPosted: Thu Sep 18, 2008 10:38 am 
Newbie

Joined: Thu Sep 18, 2008 10:18 am
Posts: 1
This is an embarrassingly basic question. In the first "Hello World" example in the book Java Persistence with Hibernate they have a very simple class:

Message
- id : Long
- text : String
- nextMessage : Message

What I'm having a difficult time with is the fact that they specify a many-to-one relationship in the Message.hbm.xml mapping file for nextMessage. I simply don't understand why it's many-to-one instead of one-to-one.

My understanding of "one to many" is that one row in some table may refer to multiple rows in another table. Whereas with "one to one", one row in one table refers to exactly one row in another. Since a Message only has "one" nextMessage, why wouldn't this relationship be one to one?

Thanks.. sorry for the basic question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 4:31 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Your question is very valid.

Think of it as if you were mapping all objects of the child class altogether, not one individual row of it.

"Many" (rows, objects) of the class Messages will have "one" parent.

The reverse association of a "one-to-many association", is a "many-to-one" association, even if each individual message only relates its one parent.

_________________
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.  [ 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.