-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problems with inheritance
PostPosted: Mon Aug 11, 2008 4:06 pm 
Newbie

Joined: Fri Feb 15, 2008 4:35 pm
Posts: 6
Hi:
I have a problem with my inheritance model: I have a hierarchical tree containing 64 subclasses in total. This in itself is not bad… Except if I try to execute a query on the parent of the tree. Hibernate generates joins to all child tables in the SQL, but I just want the data from the parent entity, not the children, and I don’t want so many joins, because the query is too big and slow…
for example:
class Person is a parent
class Worker is a child
class Work is the owner of a set of Person (a polimorfic set)
when I say, for example:
Person p = new Worker();
Work work = new Work();
work.getPeople().add;
session.save(work);

Then after the work object is persisted, if I want to obtain the people that work there:
Work work = (Work) session.get(Work.class,1);
work.getListPeople();
Which instructs Hibernate to generate join statements on Person and Worker tables to obtain the Person through Work.
If I don’t want Hibernate to generate a join statement on my child table, but rather I just want to obtain the data from the parent table, how can I do this?
Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Problems with inheritance
PostPosted: Tue Aug 12, 2008 9:03 am 
Newbie

Joined: Tue Aug 07, 2007 7:11 am
Posts: 6
"select" fetch mode should sort it out:

http://www.hibernate.org/hib_docs/core/ ... criminator


Top
 Profile  
 
 Post subject: Re: Problems with inheritance
PostPosted: Tue Aug 12, 2008 9:04 am 
Newbie

Joined: Tue Aug 07, 2007 7:11 am
Posts: 6
"select" fetch mode should sort it out:

http://www.hibernate.org/hib_docs/core/ ... criminator


Top
 Profile  
 
 Post subject: thank
PostPosted: Tue Aug 12, 2008 9:55 am 
Newbie

Joined: Fri Feb 15, 2008 4:35 pm
Posts: 6
yes, with this solution don't do a join to all the tables, but for each element in the set it do a select, and we are in the n+1 select problem


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