Hi,
I am working onn Audit functionality, using Java 1.5, Spring Core 2.5.2, Hibernate 3.2.5 and DB2.
I have implemented FlushEntityEventListener to populate Audit entity and persist it with the listener.
My code looks something like this -
public class FlushEntityEventListener extends DefaultFlushEntityEventListener
{
// ------------------------------ FIELDS ------------------------------
// --------------------- Interface FlushEntityEventListener ---------------------
public void onFlushEntity(FlushEntityEvent flushEntityEvent) throws HibernateException
{
super.onFlushEntity(flushEntityEvent);
// i construct audit entity using the flush event
Audit audit = this.constructAudit(p_flushEntityEvent);
flushEntityEvent.getSession().persist(audit);
}
My question is - is it valid to invoke persist within a Listener ?
I am getting
[i][b]org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session [/b][/i]
when persisting audit entity
I have a junit test class which has several test methods. When I execute test method individually, i dont get this execption. But when i execute the whole test class, then i get this exeception.
Did you face such problem with listeners?
|