-->
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.  [ 9 posts ] 
Author Message
 Post subject: Best way to persist inherited domain objects?
PostPosted: Tue Jun 22, 2004 10:25 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
What is the best way to store inherited domain objects? For example, I have a Business object, but there are actually 4 types of businesses. Most of them actually have only 1 field, but one of them has a few extra fields. I figured I could have 5 tables all together, but I'm not really sure how to approach it exactly.

I know hibernate supports subclasses, but I was wondering what are the performance trade offs for using this feature?

Also, if I had 5 tables, how would I figure out what type the business is? I figured I could just join the business table with all the other business type tables, but that would be low performance, would it not?

Thanks so much.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 10:58 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
I'm using postgres's inheritance by the way.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 11:20 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
Well, it doesn't appear that hibernate has direct support for postgres inheritance. I guess I just have to make 4 seperate mappings, although I don't like that idea since that's duplication, making the mapping file hard to maintain (potentially if a common field is added/edited/removed).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 11:51 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
Well, time for sleep. I'll look back tomorrow I guess.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 12:42 am 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
well, I couldn't sleep. heh.

I ended up just making seperate tables without the postgres specific way of doing inheritance and did joined-subclass and worked without a problem first crack. I guess this is better anyway since there is no duplication now.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 2:47 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
PLEASE BE PATIENT!

have you read the doc?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 12:35 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
anthony wrote:
PLEASE BE PATIENT!

have you read the doc?


Of course. It's not that I couldn't get either of them to work, it's just that I didn't know which to use with postgres's internal inheritance. I think the answer is simply none, so I just implemented the join-subclass way of doing it and got rid of those inherited tables and just made simple tables that all referenced the business table as their primary key (which worked without a hitch).

I just wanted to know what the best strategy was to avoid mapping duplication while having the benefits of using postgres's table inheritance, but since it appears that hibernate doesn't know they are inherited because postgres gives the illusion that they are not, there isn't much way for hibernate to know so I would have to duplicated 4 mappings with minor differences.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 1:12 pm 
Newbie

Joined: Thu Apr 08, 2004 10:24 am
Posts: 19
Location: Raleigh, NC
i believe there are two polymorphic devices in hibernate that will support batching (and, hence, greater performance for mass updates):

1. subclass and superclass share the same table. use a key column to indicate the subclass type. table must contain an aggregate of all columns required by all subclasses.

2. use encapsulation and model "subclasses" as separate objects. do not use the subclass feature in hibernate. do not use cascading updates or inserts.

Gavin, please correct me if i am wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 1:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
bleupen wrote:
i believe there are two polymorphic devices in hibernate that will support batching (and, hence, greater performance for mass updates):

1. subclass and superclass share the same table. use a key column to indicate the subclass type. table must contain an aggregate of all columns required by all subclasses.

2. use encapsulation and model "subclasses" as separate objects. do not use the subclass feature in hibernate. do not use cascading updates or inserts.

Gavin, please correct me if i am wrong.


Um, that sounds right, I guess...


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