-->
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: Differences between objs loaded via query vs. via get/load
PostPosted: Wed Sep 07, 2005 10:22 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I am migrating a data access layer to hibernate, a few classes at a time. I have had Partition, Meter and StoreMeter working fine for a while, and am now adding MeterChannel. Meter joins one-to-one with StoreMeter and many-to-one with Partition. MeterChannel joins many-to-one with Meter. So when I load a MeterChannel, I am non-lazily, and with fetch="join", loading Meter and Partition. I am lazily loading StoreMeter and that eagerly loads its own Partition object.

Most of the time I load objects via queries, and this is all working fine. In one case I was loading MeterChannels via load (and I've tested it with get, same results) and the last join in the sequence, from Meter to Partition, isn't being fully loaded before the postLoadEventListener is being invoked. I have code in there which checks the data in the Partition object and this is failing. The Partition object has its id loaded but no other values.

Are there any differences between session.get()/session.load() and query.list() in the loading of objects via a chain of many-to-one relationships like this? I'm happed to change my code to use a query which does the same thing as load(), but I'd like to know why this is happening.

I would imagine that there's something easily-explained at work here, but just in case, here's the important bits from the mapping file. The elipses denote extra, unimportant properties that I've removed for brevity.

Code:
<class name="PartitionImpl" table="manage.dbo.vwPartition"
    mutable="false" lazy="false">
    ...
  </class>

    <class name="StoreMeterImpl" table="Store.dbo.Meter" mutable="true" lazy="false">
    ...
    <many-to-one name="Partition"
      class="com.tml.framework.manage.impl.PartitionImpl"
      insert="false" update="false" unique="true" not-null="true" lazy="false">
  </class>

  <class name="MeterImpl" table="Meter" mutable="true">
      <many-to-one name="StoreMeter" class="StoreMeterImpl" column="StoreMeterID"
      unique="true" fetch="select" lazy="true" cascade="all"/>
    ...
    <many-to-one name="Partition" column="ManagementCompanyID"
      class="com.tml.framework.manage.impl.PartitionImpl"
      fetch="join" insert="true" update="false" not-null="true" lazy="false">
      <formula>
        (select Meter.ManagementCompanyID from Meter
         where Meter.StoreMeterID = MeterID)
      </formula>
    </many-to-one>
  </class>

  <class name="MeterChannelImpl" table="MeterChannel" lazy="false">
  ...
     <many-to-one name="Meter" column="MeterID" class="MeterImpl"
      fetch="join" not-null="true" update="false" unique="true" lazy="false"/>
  </class>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 11:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
onPostLoad() is invoked for an entity when the entity itself has been fully initialized. You should not assume that any associated objects you navigate to from the entity will have been fully initialized. They may not be until their own onPostLoad() event occurs.


Top
 Profile  
 
 Post subject: Order of loading
PostPosted: Wed Sep 07, 2005 11:48 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Not even for non-lazy loading? Is there any way of having some of my code called after an entity and all its eagerly-loaded sub-entities are loaded? Or a way of re-calling onPostLoad after the relevant sub-entities have been loaded?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 11:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
no


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.