Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Use of SessionEventListener and SessionCustomizer

I am trying to use a SessionEventListener to monitor what has changed in a transaction (entities persisted, updated, removed) in order to perform post-transaction processing in my application.   The problem I am encountering is that the UnitOfWorkChangeSet associated with the SessionEvent’s UnitOfWork is always null.  I have tried accessing the UnitOfWorkChangeSet object in a number of different postXXX methods in my listener implementation but always with the same null result.  An example of the logic is shown below:

 

public void postCommitTransaction(SessionEvent event) {

    UnitOfWork uow = event.getSession().acquireUnitOfWork();

    UnitOfWorkChangeSet changeSet = uow.getUnitOfWorkChangeSet();

    If (changeSet != null) System.out.println(changeSet);

}

 

I have tried adding my SessionEventListener directly to the newly created EntityManager

 

EntityManager em = entityManagerFactory.createEntityManager(props);

((JpaEntityManager)em.getDelegate()).getSession().getEventManager().addListener(new MyEventListener());

 

Or via a SessionCustomizer …

Public void customize(Session session) throws Exception {

    Session.getEventManager().addListener(new MyEventListener());

 

Any help or suggestions would be greatly appreciated.

 

Dennis


Back to the top