-->
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: Entity lifecycle callbacks problems
PostPosted: Tue Jun 13, 2006 8:48 am 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
I posted this topic about ActionQueue in another forum, but I believe this discussion does not concern only EJB 3.0 users. Well, actually it is not a discussion yet because nobody replied to the people who reported this.
I have been facing some problems concerning entity listeners. I'm using Hibernate version 3.2.0.cr2, which is shipped with JBoss 4.0.4. When we write an entity lifecycle callback method it is common to need some data from other entities, some times which are not related to the one being processed. When that happens we need to query for such entities. The problem is that Hibernate flushes the session before querying the database. But the callback methods are called during a flush, so bad things use to happen: if the query is executed in a pre-x callback, all pre-x callback methods are invoked again; if we are in a post-x callback and there are other operations waiting and the "inner flush" completes successfully we get a IndexOutOfBoundsException in ActionQueue:
Code:
java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
   at java.util.ArrayList.RangeCheck(ArrayList.java:547)
   at java.util.ArrayList.get(ArrayList.java:322)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:993)
   at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:267)
   at org.jboss.ejb3.entity.TransactionScopedEntityManager.flush(TransactionScopedEntityManager.java:204)
        (application trace)

One question remains: is it possible to make a "non-flushing query"? Then instead of loading all objects when retrieving the results only the objects not cached or not present in the session would be loaded directly from storage. I'm tring to patch this, but I was not able to find the right spots so far. All and any help is highly appreciated.

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
 Post subject: setFlushMode(FlushModeType.COMMIT)
PostPosted: Fri Jun 16, 2006 9:03 am 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
After a lot of struggle, I found the solution for this: Query.setFlushMode(FlushModeType.COMMIT). If I do this the flush() flow continues normally during and after query execution. It seems that attached objects are loaded instead of the underlying persistent data, even though specs state that this is not guaranteed. Too bad this is not highlighted anywhere. I shall update the JIRA bug report and some posts.

_________________
Henrique Sousa
Don't forget to rate useful responses


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.