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.