-->
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.  [ 3 posts ] 
Author Message
 Post subject: multiple tables for one column
PostPosted: Thu Feb 08, 2007 9:21 pm 
Beginner
Beginner

Joined: Mon Jun 19, 2006 9:21 pm
Posts: 25
So, while I'm pretty sure I would use the descriminator construct to do this, I'm just not sure how.

Basically I have one table, comments, that has a column that links to multiple tables based on a type column within comments. IE: If comments_type is 'blog' then the reference_id is a foreign key of the blog table. If the comments_type is 'pictures' then the reference_id is a foreign key of the media table, and so on and so forth.

For java I'm simply going to use inhertance to make them all have the same standard media properties (including id) and generics to instantiate the comment class with the appropriate media class. But I'm just not sure how to translate this when mapping, or how to tell hibernate which class to use for the generic comment class (or if I can use a generic comment class for that matter).

Any help would be appreciated as I couldn't find any examples of this...the only I found with discriminators didn't fit my situation at all.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 12:26 am 
Expert
Expert

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

You could do it by bag. But for that you should have separate PK for each table. or what you can do ,use different range of PK for comments parent table.

Avoid this type of design

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 1:56 am 
Beginner
Beginner

Joined: Mon Jun 19, 2006 9:21 pm
Posts: 25
Actually, I'm not sure if I explained it right. There isn't a parent table of comment. Comment has a many to one relation to it's reference's (blog, media, etc). The comment for every type of reference is identical, there is no different between them.

While I know my alternative (realistic one) is to create an intermediate table for each reference type possible, that would break the many to one relation (making it many to many) and it would produce a lot of little tables everywhere which aren't needed. My preference is to keep it a many to one relation, and since I'll know what comment type I want based on the context of the user's actions, this seems like a fairly straight forward approach to me with no waste.

For the java I'll be instantiating the comment class w/ generics, so it'll be something like

Comment<Blog> blogComment = new Comment<Blog>();

which will tell the class to use a blog for the reference class. With generics, it seems much better to use the proper class in comment rather then have five of them, four of which aren't being used (plus I don't think you could do that anyway since they would relate to the same column). One of my questions was whether or not Hibernate could deal w/ generics in this way...I'm hoping it can since generics are so powerful, and keep things very organized.

Hopefully that explains better what I have in mind.


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