IndexOutOfBoundsException when a flush occurs during validation inside a flush
------------------------------------------------------------------------------
Key: HHH-3406
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3406
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.6
Environment: 3.2.6ga, oracle11g, tomcat 6.0.16, spring 2.5.1, redhat5.2 or
windows XP or debian etch
Reporter: vincent Larchet
Say we have entity A:
@Entity
public class A {
[...]
@AssertTrue
public boolean validateSomeCondition(){
//call service S
B=S.loadEntityB()
[.... do some stuff with B...]
}
}
In my hibernate session I modifiy several entities among them A1, A2, A3 (instances of A),
then I flush the session that firsts validates A1. Inside A1.validateSomeCondition() I
have to call a service that loads some data inside its own transaction, thus when it
returns a commit is triggered that is intercepted an hibernate flushes its session, and
not only entities bound to this transaction but the WHOLE session (including A2, A3 !!!).
Then validation of A1 finishes successfully and A1 is saved to db, but right after that
this exception occurs
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:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
at
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at
org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:596)
at
org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:709)
at
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678)
at
org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:319)
at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
[...]
I do not really know if flushing A2,A3 entites inside the 2nd flush is an issue or not (I
do not mind actually...), so I suggest this quick fix:
inside ActionQueue method
private void executeActions(List list)
throws HibernateException
{
int size = list.size();
for(int i = 0; i < size; i++)
execute((Executable)list.get(i));
list.clear();
session.getBatcher().executeBatch();
}
replace the "static" int size = list.size(); for(int i = 0; i <
size; i++) by an iterator...
thx
vincent
NB: we use OpenSessionInViewFilter
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira