Hello, all! I've got a problem with post-update event and execution of a query in the same session.
I want to get list of objects after update occured. The code is:
Code:
public class VendorUpdateEventListener implements org.hibernate.event.PostUpdateEventListener {
public void onPostUpdate(PostUpdateEvent event) {
if(event.getEntity() instanceof Vendor){
Vendor vendor = (Vendor)event.getEntity();
Criteria crit = event.getSession().createCriteria(Goods.class);
crit.add(Restrictions.eq("vendor", vendor));
crit.add(Restrictions.eq("available", true));
List goods = crit.list();
System.out.println(goods.size());
}
}
}
The query works well, but later in flush java.lang.IndexOutOfBoundsException occures.
Here is the stacktrace:
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:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:732)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
at ua.od.intes.isales.core.dao.VendorsDaoImpl$$EnhancerByCGLIB$$69f9d2af.saveVendor(<generated>)
at ua.od.intes.isales.core.service.VendorsServiceImpl.save(VendorsServiceImpl.java:98)
at ua.od.intes.isales.core.service.VendorsServiceImpl$$FastClassByCGLIB$$f88f878f.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:160)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
at ua.od.intes.isales.core.service.VendorsServiceImpl$$EnhancerByCGLIB$$9ca8e19.save(<generated>)
...
vendor in class Goods in many-to-one relation to class Vendor. It seems to me this is a bug, so how can I do it in some other way?
Thank you for replies and sorry for my terrible English.