tenwit wrote:
onFlushDirty is called once per interceptor, every time a dirty object is flushed. If there are hundreds of dirty objects in your session, you'll get hundreds of onFlushDirty calls.
IMHO,the onFlushDirty method is called when a method-spanned transaction is over and hibernate is going to flush all the changed data to database.if onflushDirty returns true,the dirty properties will be recalcaulated. but I neend the more details to know what caused onFlushDrity called many times on the same database result,and how can I avoid it from being called too many times.
e.g.
an OrderVO has many-to-many relation to OrderItemVO.
public class BO{
public Session openSession() {
return SessionFactoryUtils.getSession(getSessionFactory(), false);
}
public void bizProc(Long id){
a(id);
b(id);
}
public void a(Long id){
OrderVO obj=(OrderVO)openSession().load(OrderVO.class,id);
obj.setXXX();
Iterator it=obj.getOrderItems().iterator();
while (it.hasNext()) {
OrderItemVO item=(OrderItemVO )it.next();
item.setYYY();
}
}
public void b(Long id){
OrderVO obj=(OrderVO)openSession().load(OrderVO.class,id);
obj.setXXX();
Iterator it=obj.getOrderItems().iterator();
while (it.hasNext()) {
OrderItemVO item=(OrderItemVO )it.next();
item.setYYY();
}
}
}
regard to the sample code above, when the bizProc(id) is executed and transaction is commited, a lot of calls is made to onFlushDirty method which the first parameter of it is an OrderVO entity,and so I got a lot of history objects inserted into the history table.
btw,I use open session in view pattern.
what's wrong? and can I do something to avoid?
Thanks again.
Best Regards,
Steven