-->
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 subclasses not using fetchmode join
PostPosted: Thu Sep 16, 2010 9:53 am 
Newbie

Joined: Thu Sep 16, 2010 9:46 am
Posts: 2
Hi,

I'm having weird issues trying to use fetch="join" on the properties of more than one subclass of my hibernate mapping file.

First, the situation: I have a constellation of one-to-many tables related by foreign key to a single parent table. The parent table defines the superclass, then overlapping subsets of the related tables define the subclasses. So subclass A will have sets of type (X, Y, and Z) and subclass B will have sets of type (X, V, and W) .

The Hibernate Mapping file looks like this:
Code:
<hibernate-mapping>
   <class name="ParentClass" table="SCHEMA.BASE" polymorphism="implicit">
      <discriminator column="DISC_COLUMN" type="string" insert="false"/>
      <...parent properties...>
      <subclass name="A" discriminator-value="DISC_A">
         <set name="prop_x" fetch="join">
            <key column="BASE_ID_FK" />
            <one-to-many class="X" />
         </set>
         <set name="prop_y" fetch="join">
            <key column="BASE_ID_FK" />
            <one-to-many class="Y" />
         </set>
         <set name="prop_z" fetch="join">
            <key column="BASE_ID_FK" />
            <one-to-many class="Z" />
         </set>
      </subclass>
      <subclass name="B" discriminator-value="DISC_B">
         <set name="prop_x" fetch="join">
            <key column="BASE_ID_FK" />
            <one-to-many class="X" />
         </set>
         <set name="prop_v" fetch="join">
            <key column="BASE_ID_FK" />
            <one-to-many class="V" />
         </set>
         <set name="prop_w" fetch="join">
            <key column="BASE_ID_FK" />
            <one-to-many class="W" />
         </set>
      </subclass>
   </class>

The Criteria query used looks like this:
Code:
   Criteria criteria = hSession.createCriteria(ParentClass.class);
      .addOrder(Order.asc("order_column"))
      .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);


Now, when I execute that Criteria (in order to get both As and Bs back), the select statement output left outer joins V, W, X, Y, and Z (just like you'd think it would). Attempts to access a returned object of type A's properties are successful without Lazy loading (as I want it to be), but any attempt to access an object of type B's properties results in them being lazy loaded, even though they should be available.

But it gets weirder! Which subclass has immediate access to the SELECTed information is position dependent! If I swap subclass B above subclass A in the mapping file, then it works fine, while class A does the lazy loading.

I've also tried moving class A out to an external mapping file, but the behavior is the same, it still insists on lazy loading its properties.

If anybody has seen this before and has a solution, or even has a suggestion about what I should try next, I would be extremely grateful. If I can provide any further information please don't hesitate to let me know. It seems to me that any behavior that treats one sibling differently from another is not working as designed.

Thanks for your time,

matt


Last edited by matt.levan on Thu Sep 16, 2010 12:49 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Multiple subclasses not using fetchmode join
PostPosted: Thu Sep 16, 2010 12:15 pm 
Newbie

Joined: Mon Sep 14, 2009 2:09 pm
Posts: 2
I'm not an expert, but I think that all of those fetch=join will result in a cartesian product that will probably cause an OutOfMemoryError, if I understand it correctly.
The size of the number of tuples returned will be M x N x O x P where M,N,O, and P are the sizes of the eager fetched collections. If each collection had only 10 items, that would be 10,000 objects for a single query. Most of that data will be redundant.

You want to use lazy loading when you have that many collection properties.


Top
 Profile  
 
 Post subject: Re: Multiple subclasses not using fetchmode join
PostPosted: Thu Sep 16, 2010 12:49 pm 
Newbie

Joined: Thu Sep 16, 2010 9:46 am
Posts: 2
Thanks for responding, les2. Everyone knows that this isn't the ideal situation, but it's what I have to put up with for a while. All the child tables are pretty sparse, so while it is multiplicative, it's not quite as bad as your example.

I should add to my original post that we're using Hibernate 3.2.5.ga.

Since my first post, I've removed all the 'lazy="false"' references, they don't make a difference in this case and could be distracting from the heart of the issue.

Thanks,

matt


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.