-->
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: lazy collection loaded during "flush"
PostPosted: Thu Mar 26, 2009 11:33 am 
Newbie

Joined: Tue May 11, 2004 11:32 am
Posts: 16
I have a class with a collection marked as lazy. None of my code is interacting with the collection property, but I'm noticing that it is being loaded during a flush.

I stepped through some of the hibernate code (specifically the PojoEntityTuplizer and AbstractEntityTuplizer) and saw that it wasn't treated "channels" as lazy. I *think* it's because lazyAvailable is false (inside EntityMetamodel) due to the class level lazy attribute on "Playlist". I didn't think that had anything to do with whether or not a lazy collection is loaded though. I fear I'm going down the wrong path here, so thought I'd ask for help :)

thanks
sam

Stack trace from a dumpStack I added to getChannels
Code:
java.lang.Exception: Stack trace
   at java.lang.Thread.dumpStack(Thread.java:1206)
   at Playlist.getChannels(MediaCollection.java:116)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
   at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:277)
   at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValue(AbstractEntityPersister.java:3586)
   at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
   at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
   at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
   at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
   at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
   at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:811)
           ... snipped ...


The mapping:

Code:
  <class name="Playlist" table="playlist" lazy="false" discriminator-value="0">
    <cache usage="nonstrict-read-write"/>   
    <id name="id" column="id" type="long">
      <generator class="MyIdentifierGenerator"/>     
    </id>
    <discriminator column="discriminator" type="integer"/>
    <version name="version" column="version" type="integer"/>
    <set name="channels" lazy="true" inverse="true" cascade="all-delete-orphan">
      <key column="playlist_id"/>
      <one-to-many class="Channel"/>
    </set>
       <subclass name="VideoPlaylist" lazy="false" discriminator-value="1" >
         
   </subclass>
   <subclass name="AudiaPlaylist" lazy="false" discriminator-value="2">
   </subclass>   
  </class>




Hibernate version: 3.2.6


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 26, 2009 2:41 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Are you actually seeing that Hibernate executes SQL to load the collection from the database?

From what I can interpret from the stacktrace it seems like Hibernate is doing an automatic flush as a preparation step before executing a query. One part of the flush is to check the "dirtiness" of all entities and collections. So it calls Playlist.getChannels() to get a reference to the collection. This is what you see in the stacktrace. When Hibernate has got the reference to the collection there are probably more checks to see if it is a lazy collection, if it has been initialized and so on.

In other words, the call to Playlist.getChannels() is part of the dirty-checking mechanism and doesn't mean that Hibernate has initialized the collection.

The simplest way to verify if Hibernate actually initializes the collection is to enable SQL logging. See http://www.hibernate.org/hib_docs/v3/re ... gging.html for information about this.


Top
 Profile  
 
 Post subject: Re: lazy collection loaded during "flush"
PostPosted: Tue May 26, 2009 1:36 pm 
Newbie

Joined: Tue May 26, 2009 5:35 am
Posts: 7
I have the same problem. viewtopic.php?f=1&t=997113


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.