getting the active JPA UnitOfWork [message #387945] |
Tue, 19 May 2009 19:09  |
Eclipse User |
|
|
|
I wrote an SessionEventListener with a preCommitTransaction(SessionEvent
evt) method and am trying to figure out how to get from the session in the
event to the UnitOfWork representing the JPA EntityManager. Is this
possible?
I am trying to get to the changesets for the JPA entities...
I looked at JPAHelper but did not see any methods that seem to provide a
path from session to EntityManager. I am thinking I need the EntityManager
so I can do this:
JPAHelper.getEntityManager(em).getUnitOfWork().getCurrentCha nges(), but
perhaps there is another path?
Thanks,
Frank
|
|
|
|
Re: getting the active JPA UnitOfWork [message #387958 is a reply to message #387956] |
Tue, 19 May 2009 20:44   |
Eclipse User |
|
|
|
Unfortunatley that causes a ClassCastException, apparently getSession()
returns a ClientSession and it cannot be casted to UnitOfWork. I also
tried getActiveUnitOfWork() but that returns null, and I assume
acquireUnitOfWork() creates a new one....
James wrote:
> You should be able to just get the UnitOfWork from the SessionEvent (the
> Session is a UnitOfWork).
> UnitOfWork uow = (UnitOfWork) event.getSession();
> ---
> James
> http://www.nabble.com/EclipseLink---Users-f26658.html
|
|
|
Re: getting the active JPA UnitOfWork [message #388102 is a reply to message #387958] |
Tue, 19 May 2009 22:57  |
Eclipse User |
|
|
|
Problem solved. I should have overridden the postCommitUnitOfWork method,
not the preCommitTransaction method. In that method the cast is
successful, which makes sense. Now I have access to the changes to all the
JAP entities. Now all I have to figure out is how to interpret that
UnitOfWorkChangeSet structure..... ;-)
Frank Sauer wrote:
> Unfortunatley that causes a ClassCastException, apparently getSession()
> returns a ClientSession and it cannot be casted to UnitOfWork. I also
> tried getActiveUnitOfWork() but that returns null, and I assume
> acquireUnitOfWork() creates a new one....
> James wrote:
>> You should be able to just get the UnitOfWork from the SessionEvent (the
>> Session is a UnitOfWork).
>> UnitOfWork uow = (UnitOfWork) event.getSession();
>> ---
>> James
>> http://www.nabble.com/EclipseLink---Users-f26658.html
|
|
|
Powered by
FUDForum. Page generated in 0.03447 seconds