-->
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.  [ 1 post ] 
Author Message
 Post subject: Lazy loading polymorpic data instead of massive outer join
PostPosted: Fri Jul 11, 2008 3:18 pm 
Newbie

Joined: Fri Jul 11, 2008 1:00 pm
Posts: 1
Are there major performance ramifications of the way hibernate implements its query when using discrimination and the hierarchy contains many subclasses? For example, we currently have a structure similar to this (only we have around 10-15 subclasses):

Code:
class Item { ... }
|--class SomeItem extends Item { ... }
   |--class PlainItem extends SomeItem { .... }
   |--class FancyItem extends SomeItem { .... }
|--class SomeOtherItem extends Item { .... }
   |--  class AnotherClass extends SomeOtherItem { ... }
|--class ThisOtherItem extends Item { .... }


When using InheritanceType.JOINED, PolymorphismType.IMPLICIT (the default), and a DiscriminatorFormula the sql which gets generated when one tries to return an object passing in the topmost class will look something like this:
Code:
java code:
  Item i = (Item)session.load(Item.class, new Long(1));
  System.out.println(i);

generated sql:
  select
    lots and lots of aliased fields,
    case when item0_5_.id is not null then 5 when item0_6_.id is not null then 6 when item0_3_.id is not null then 3 when item0_1_.id is not null then 1 when item0_2_.id is not null then 2 when item0_4_.id is not null then 4 when item0_.id is not null then 0 end as clazz_0_
from
    _item item0_
      left outer join SomeItem item0_1_ on item0_.id=item0_1_.id
      left outer join SomeOtherItem item0_2_ on item0_.id=item0_2_.id
      left outer join AnotherClass item0_3_ on item0_.id=item0_3_.id
      left outer join ThisOtherItem item0_4_ on item0_.id=item0_4_.id
      left outer join PlainItem item0_5_ on item0_.id=item0_5_.id
      left outer join FancyItem item0_6_ on item0_.id=item0_6_.id
  where item0_.id=?


That's a lot of joining going on, not to mention each table might have LOTS of fields.

Has this historically been an ok approach? It seems to me that this many joins are going to have a negative impact on our application but I don't have any stress testng capabilites to "just try it" in. (not to mention - migrating all the code is a very large effort).

Is there any alternative to returning every row at one and only returning enough data to discriminate the class with and then fetch subsequent data 'lazy'?

At this time we have opted to maintain "detail" objects which are including into the hierarchy via composition rather than inheritance but once we get more than one level deep this just starts to be cumbersome.

I hope that makes sense - if not I'll be happy to provide more information.

Any ideas? I'm open to both using annotations or hibernate config though annotations are preffered... We can't find any combination that makes this work...

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.