Skip to main content

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

I think the main issue you are having is your call to acquireUnitOfWork(). That will create a new UnitOfWork -> with no changes.

Try calling postCommitUnitOfWork(). The session attached to your SessionEvent should be the UnitOfWork.

-Tom

On 19/01/2012 5:10 PM, Dennis Fuglsang wrote:
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



_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top