-->
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: Low performance (2-phase load) with optional many-to-one
PostPosted: Fri Sep 19, 2008 6:27 pm 
Newbie

Joined: Mon Dec 05, 2005 1:03 pm
Posts: 10
Hibernate version: 3.2.4sp1

I've found a similar bug on JIRA (bug HB-12) that is supposed to be fixed, but I still encounter the same [similar] problem:
http://opensource.atlassian.com/project ... owse/HB-12

I'm using the Criteria API to retrieve the events along with the device info. Since I'm using fetch="join", Hibernate also loads the parent, which is fine. However, as described in bug HB-12, if the parent is null (it's optional after all), an extra load is performed.

Although this is not a n+1 select problem, it could be one if none of the parents exists.

I've tracked down the problem to the 2-phase loading mechanism:
CriteriaLoader.initializeEntitiesAndCollections()
--> TwoPhaseLoad.initializeEntity()
--> ManyToOneType(EntityType).resolve()
...
finally, the session dispatch the Load event, which causes the LoadEventListener to try to load the parent entity from the session cache. If it was not in the cache (was null), then a separate load will be performed. The extra load is useless because it'd still get a null parent.

I'd expect Hibernate to remember that the parent was null in the initial select and ignore the 2nd load.

Is this a bug? Is there a solution/workaround?


Top
 Profile  
 
 Post subject: Re: Low performance (2-phase load) with optional many-to-one
PostPosted: Sat Sep 20, 2008 1:56 am 
Newbie

Joined: Mon Dec 05, 2005 1:03 pm
Posts: 10
lukeda wrote:
I'm using the Criteria API to retrieve the events along with the device info.


Sorry, here are the mappings for the problem that I was describing:

Event.hbm.xml
Code:
  <class name="Event" table="event" lazy="true">
    ...
    <property name="deviceURI" type="string" column="deviceURI"/>
    <many-to-one name="deviceInfo" class="DeviceInfo" update="false" insert="false" fetch="join" not-found="ignore">
        <column name="deviceUri"/>
    </many-to-one>
  </class>


DeviceInfo.hbm.xml
Code:
  <class name="DeviceInfo" table="deviceinfo" lazy="true">
    <composite-id class="DevicePK" mapped="true">
      <!--<key-property name="timestamp" type="long" column="timestamp"/>-->     
      <key-property name="uri" type="string" column="uri"/>
    </composite-id>
    <property name="label" type="string" column="label"/>
  </class>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2008 11:26 am 
Newbie

Joined: Mon Dec 05, 2005 1:03 pm
Posts: 10
The Hibernate gurus out there, please just give a short answer as to yes or no it's a known shortcoming. That an extra select is issued for each child when the parent is optional and null.


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.