-->
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: Nullable many-to-one relation prevents lazy loading
PostPosted: Tue Oct 21, 2008 2:31 pm 
Newbie

Joined: Tue Oct 21, 2008 2:09 pm
Posts: 1
Hibernate version: 3.2.4

Name and version of the database you are using: Oracle 10gR2


I have the following mappings (actual names changed):

Parent table:

Code:
<hibernate-mapping>

    <class name="ClassParent" table="ParentT">

        <composite-id name="id" class="...">
            <key-property name="parentSeqNbr" type="big_decimal">
                <column name="PARENT_SEQ_NBR" precision="10" scale="0" />
            </key-property>
            <key-property name="parentSiteCd" type="string">
                <column name="PARENT_SITE_CD" length="11" />
            </key-property>
        </composite-id>
    </class>
</hibernate-mapping>


Child table:

Code:
<hibernate-mapping>

    <class name="ClassChild" table="ChildT">

        <composite-id name="id" class="...">
            <key-property name="childSeqNbr" type="big_decimal">
                <column name="CHILD_SEQ_NBR" precision="10" scale="0" />
            </key-property>
            <key-property name="childSiteCd" type="string">
                <column name="CHILD_SITE_CD" length="11" />
            </key-property>
        </composite-id>

        <many-to-one name="parentRecord" not-found="ignore" class="ClassParent" fetch="select" lazy="proxy" >
            <column name="PARENT_SEQ_NBR" precision="10" scale="0" />
            <column name="PARENT_SITE_CD" length="11" />
        </many-to-one>

    </class>
</hibernate-mapping>


When I query the child table by running some hql, if it has a parent record associated to it, the record gets automatically loaded - no proxy created. After doing some digging, it seems to me that this is caused by the code in SessionImpl.internalLoad method:

Code:
   public Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable) throws HibernateException {
      // todo : remove
      LoadEventListener.LoadType type = nullable ?
            LoadEventListener.INTERNAL_LOAD_NULLABLE :
            eager ? LoadEventListener.INTERNAL_LOAD_EAGER : LoadEventListener.INTERNAL_LOAD_LAZY;
      LoadEvent event = new LoadEvent(id, entityName, true, this);
      fireLoad(event, type);
      if ( !nullable ) {
         UnresolvableObjectException.throwIfNull( event.getResult(), id, entityName );
      }
      return event.getResult();
   }


It looks like if nullable is true, then type is set to LoadEventListener.INTERNAL_LOAD_NULLABLE, which calls setAllowProxyCreation(false). This prevents DefaultLoadEventListener from creating a proxy for this entity. Also, there's a "todo:remove" comment in this method, which makes me think this is a known issue - is it? I couldn't find any resolution on the web.

I do have proxying enabled in general in the app. It works for not-nullable relationships, and I can actually see the CGLIB proxy class for the Parent class in the heap dump from this app (even though there are no instances of the proxy class - I believe the class is generated anyway on Hibernate initialization).

I appreciate any insight or help with this issue.

Thanks,

Andrey


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.