This content has been marked as final. Show 5 replies
Try using a pre/postMergeUnitOfWorkChangeSet event, and look up the 'UnitOfWorkChangeSet' property to get the changeset from the event. If you are going to use the postCommitUnitOfWork, the session in the event is the UnitOfWork, which you can use to call getUnitOfWorkChangeSet() or getAllClones if you wish.
The changesets will contain all the changes made in the transaction.
I'm using postCommitUnitOfWork(). From the event when I'm trying ot get unitofwork, i'm always getting null.
Here is what I'm doing :
added this entry to persistence.xml
<property name="toplink.session.customizer" value="jpa.tests.MySessionCustomizer"/>
customize() method in MySessionCustomizer is:
public void customize(Session session) throws Exception
PostCommitEventListener listener = new PostCommitEventListener();
And overriden method in PostCommitEventListener is:
public void postCommitUnitOfWork(SessionEvent event)
Session session = event.getSession();
UnitOfWork acquireUnitOfWork = session.getActiveUnitOfWork();
UnitOfWorkChangeSet unitOfWorkChangeSet = acquireUnitOfWork.getUnitOfWorkChangeSet();
IdentityHashtable allChangeSets = unitOfWorkChangeSet.getAllChangeSets();
Enumeration enumeration = allChangeSets.elements();
System.out.println("enumeration has more elements: " + enumeration.hasMoreElements());
When I've debugged, I've got this exception.
Nested units of work are not supported in TopLink Essentials
How do I get committed entity from SessionEvent in PostCommitUnitOfWork()?
The session you are getting from the event using event.getSession() is the UnitOfWork, which is why you get an exception when you then try to call getActiveUnitOfWork on it - you are getting a UOW from a UOW which is not supported. Cast the session to a UnitOfWork to call getAllChangeSets on it.