-->
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: about many-to-one relationship doubt
PostPosted: Sat Mar 17, 2007 9:58 am 
Beginner
Beginner

Joined: Sat Mar 03, 2007 5:32 am
Posts: 20
i have 2 tables, tbl_thread and tbl_message. in tbl_message there is one column 'threadId' which is a FK to tbl_thread 'id' column.
A thread could have many messages tagged to it.
so how do i do the mapping?? and how should i get the value for the 'threadId' column?

thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 18, 2007 2:17 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Do you want this relationship to be unidirectional or bidirectional? If I'm right, you're managing some king of forum or something like that.

If so, it seems to me it would make sense to map a List (or Set) of Messages in a Thread. So a parent relationship should do what you want.

Map a List (see bag) or Set (set) mappings and map the many-to-one reverse relation if you want.

Please read the reference documentation: http://www.hibernate.org/hib_docs/v3/re ... child.html

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 18, 2007 10:46 pm 
Beginner
Beginner

Joined: Sat Mar 03, 2007 5:32 am
Posts: 20
i have another question. if for example, i have 2 class file: reply and message. reply will inherit from message. so how do i do the mapping? Message could have the following attribute: id, messageId, creationDate. Reply could have the following attribute: modifiedDate, and it will take the message's id and messageId attribute. How do i do the mapping for the both class? thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 4:07 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
See reference documentation http://www.hibernate.org/hib_docs/v3/re ... tance.html

If you have problem using it, then come back :)

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 2:08 am 
Beginner
Beginner

Joined: Sat Mar 03, 2007 5:32 am
Posts: 20
i have seen this website before. but i don't quit understand. could u do a simple explanation.

my doubt:
1) there is only 1 mapping file needed? the mapping file is based on the parent?
2) the subclass is the child?
3) what is discriminator-value?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 6:26 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
fangEve wrote:
i have seen this website before. but i don't quit understand. could u do a simple explanation.

my doubt:
1) there is only 1 mapping file needed? the mapping file is based on the parent?

Better read the documentation about the different strategy of mappings. Moreover, to understand those solutions, you should think about how you would map inheritance inside an RDBMS.

fangEve wrote:
2) the subclass is the child?

The child of what? Are you speaking about child in inheritance or in a composition relationship?

fangEve wrote:
3) what is discriminator-value?

This is one part of one solution to map inheritance. For example, you can decide to map all persons to a single table. Hibernate will then use this field to know if the row is a women or a man, say.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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.