-->
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.  [ 2 posts ] 
Author Message
 Post subject: BUG?: initializeFromCache for PersistentBag
PostPosted: Sun Sep 30, 2007 8:15 pm 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Hi. I wasn't able to catch the bug in the route case for now. It occurs very indeterministic. Our object structure is quite complicated. Anyway, the problem occurs when hibernate initializes collections from cache, in PersistentBag.initializeFromCache method:
Code:
      Serializable[] array = (Serializable[]) disassembled;
      int size = array.length;
      beforeInitialize( persister, size ); //(1)
      for ( int i = 0; i < size; i++ ) {
         Object element = persister.getElementType().assemble( array[i], getSession(), owner ); //(2)
         if ( element!=null ) {
            bag.add( element ); //(3)
         }
      }

Time to time (that is what I haven't find out yet precisely), some collection is loaded with duplicate entries, and it should not. Like, there should be entries 1,2,3, and there are: 1,2,3,2,3. (2 and 3 with same identity).

After some not very deep debugging, I found out, that in this method, the line with (2), can 'refill' the bag. So, the debug was like (assume collection with 3 elements [1,2,3]):
1. at line with (1) the collection was newly created.
2. at first cycle, 1. element was taken, and put to collection (2) and (3) [1]
3. at second cycle, 2. element was taken (2) and, the bag was filled with 2 . and 3. element [1,2,3]
3. than at step on line (3) the second element was put to the collection again [1,2,3,2]
4. at third cycle, 3. element was taken (2) and put to bag (3), result: [1,2,3,2,3]

Small fix like this, resolved the problem:
Code:
      Serializable[] array = (Serializable[]) disassembled;
      int size = array.length;
      List<Object> elements = new ArrayList<Object>(size);
      for ( int i = 0; i < size; i++ ) {
         Object element = persister.getElementType().assemble( array[i], getSession(), owner );
         if ( element!=null ) {
            elements.add( element );
         }
      }
      beforeInitialize( persister, size );
      for ( Object element : elements ) {
         bag.add( element );
      }


Is this enough for entering a bug? I know I could hunt the bug deeper (I probably will), but currently there is no time for this. Maybe, it is already resolved, or you encountered it, or someone will look at it and will know where the problem lies.

Hibernate version:3.3.1 GA + ehcache 1.3.0

Mapping documents: second level cache on

Code between sessionFactory.openSession() and session.close(): I was not able to simulate it easily

Full stack trace of any exception that occurs: no exception

Name and version of the database you are using: oracle xe

The generated SQL (show_sql=true): ...

Debug level Hibernate log excerpt:

I found the Stack, how the problem happens:
Code:
       
   PersistentBag.beforeInitialize(CollectionPersister, int) line: xx //here is the same collection reinitialized again, and loaded again   
   CollectionLoadContext.getLoadingCollection(CollectionPersister, Serializable) line: 127   
   EntityLoader(Loader).readCollectionElement(Object, Serializable, CollectionPersister, CollectionAliases, ResultSet, SessionImplementor) line: 1003   
   EntityLoader(Loader).readCollectionElements(Object[], ResultSet, SessionImplementor) line: 646   
   EntityLoader(Loader).getRowFromResultSet(ResultSet, SessionImplementor, QueryParameters, LockMode[], EntityKey, List, EntityKey[], boolean) line: 591   
   EntityLoader(Loader).doQuery(SessionImplementor, QueryParameters, boolean) line: 701   
   EntityLoader(Loader).doQueryAndInitializeNonLazyCollections(SessionImplementor, QueryParameters, boolean) line: 236   
   EntityLoader(Loader).loadEntity(SessionImplementor, Object, Type, Object, String, Serializable, EntityPersister) line: 1860   
   EntityLoader(AbstractEntityLoader).load(SessionImplementor, Object, Object, Serializable) line: 48   
   EntityLoader(AbstractEntityLoader).load(Serializable, Object, SessionImplementor) line: 42   
   SingleTableEntityPersister(AbstractEntityPersister).load(Serializable, Object, LockMode, SessionImplementor) line: 3044   
   DefaultLoadEventListener.loadFromDatasource(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 395   
   DefaultLoadEventListener.doLoad(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 375   
   DefaultLoadEventListener.load(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 139   
   DefaultLoadEventListener.proxyOrLoad(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 195   
   DefaultLoadEventListener.onLoad(LoadEvent, LoadEventListener$LoadType) line: 103   
   SessionImpl.fireLoad(LoadEvent, LoadEventListener$LoadType) line: 878   
   SessionImpl.internalLoad(String, Serializable, boolean, boolean) line: 846   
   ManyToOneType(EntityType).resolveIdentifier(Serializable, SessionImplementor) line: 557   
   ManyToOneType.assemble(Serializable, SessionImplementor, Object) line: 196   
   TypeFactory.assemble(Serializable[], Type[], SessionImplementor, Object) line: 420   
   CacheEntry.assemble(Serializable[], Object, Serializable, EntityPersister, Interceptor, EventSource) line: 96   
   CacheEntry.assemble(Object, Serializable, EntityPersister, Interceptor, EventSource) line: 82   
   DefaultLoadEventListener.assembleCacheEntry(CacheEntry, Serializable, EntityPersister, LoadEvent) line: 553   
   DefaultLoadEventListener.loadFromSecondLevelCache(LoadEvent, EntityPersister, LoadEventListener$LoadType) line: 508   
   DefaultLoadEventListener.doLoad(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 357   
   DefaultLoadEventListener.load(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 139   
   DefaultLoadEventListener.proxyOrLoad(LoadEvent, EntityPersister, EntityKey, LoadEventListener$LoadType) line: 195   
   DefaultLoadEventListener.onLoad(LoadEvent, LoadEventListener$LoadType) line: 103   
   SessionImpl.fireLoad(LoadEvent, LoadEventListener$LoadType) line: 878   
   SessionImpl.internalLoad(String, Serializable, boolean, boolean) line: 846   
   ManyToOneType(EntityType).resolveIdentifier(Serializable, SessionImplementor) line: 557   
   ManyToOneType.assemble(Serializable, SessionImplementor, Object) line: 196   
   PersistentBag.initializeFromCache(CollectionPersister, Serializable, Object) line: xxx //NOW HERE IS THE Bag initializing from cache, it fails, see top of the stack!!   
   CollectionCacheEntry.assemble(PersistentCollection, CollectionPersister, Object) line: 35   
   DefaultInitializeCollectionEventListener.initializeCollectionFromCache(Serializable, CollectionPersister, PersistentCollection, SessionImplementor) line: 130   
   DefaultInitializeCollectionEventListener.onInitializeCollection(InitializeCollectionEvent) line: 48   
   SessionImpl.initializeCollection(PersistentCollection, boolean) line: 1716   
   PersistentBag(AbstractPersistentCollection).forceInitialization() line: 454   
   StatefulPersistenceContext.initializeNonLazyCollections() line: 794   
   QueryLoader(Loader).doQueryAndInitializeNonLazyCollections(SessionImplementor, QueryParameters, boolean) line: 241   
   QueryLoader(Loader).doList(SessionImplementor, QueryParameters) line: 2220   
   QueryLoader(Loader).listIgnoreQueryCache(SessionImplementor, QueryParameters) line: 2104   
   QueryLoader(Loader).list(SessionImplementor, QueryParameters, Set, Type[]) line: 2099   
   QueryLoader.list(SessionImplementor, QueryParameters) line: 378   
   QueryTranslatorImpl.list(SessionImplementor, QueryParameters) line: 338   
   HQLQueryPlan.performList(QueryParameters, SessionImplementor) line: 172   
   SessionImpl.list(String, QueryParameters) line: 1121   
   QueryImpl.list() line: 79   
   QueryImpl.getResultList() line: 66   
   //some stack before, uninportant


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 02, 2007 4:56 am 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
I added stack trace of the problem, can anyone help?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.