Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » getting the active JPA UnitOfWork
getting the active JPA UnitOfWork [message #387945] Tue, 19 May 2009 15:09 Go to next message
Frank Sauer is currently offline Frank Sauer
Messages: 14
Registered: July 2009
Junior Member
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 #387956 is a reply to message #387945] Tue, 19 May 2009 16:10 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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


James : Wiki : Book : Blog : Twitter
Re: getting the active JPA UnitOfWork [message #387958 is a reply to message #387956] Tue, 19 May 2009 16:44 Go to previous messageGo to next message
Frank Sauer is currently offline Frank Sauer
Messages: 14
Registered: July 2009
Junior Member
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 18:57 Go to previous message
Frank Sauer is currently offline Frank Sauer
Messages: 14
Registered: July 2009
Junior Member
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
Previous Topic:Blob question
Next Topic:How to flush EclipseLink Query cache for a specific query?
Goto Forum:
  


Current Time: Thu Aug 21 02:35:38 EDT 2014

Powered by FUDForum. Page generated in 0.03899 seconds