Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » DescriptorEventAdapter merging and object
DescriptorEventAdapter merging and object [message #382751] Mon, 20 October 2008 01:10 Go to next message
Douglas Hammond is currently offline Douglas Hammond
Messages: 8
Registered: July 2009
Junior Member
Thank you for your helo in advance. As You can see i am new to using
eclipselink and have many questions as I try to get a handle on how it
works.

I hava a DescriptorEventAdapter that does this

public void aboutToInsert(DescriptorEvent event) {
User currentUser = UserUtil.getCurrentUser();

Date now = new Date();
event.updateAttributeWithObject("dateUpdated", now);
event.updateAttributeWithObject("dateCreated", now);
event.updateAttributeWithObject("createdBy", currentUser);
event.updateAttributeWithObject("updatedBy", currentUser);
}

The problem is the user gotten from UserUtil in not merged into the
entitymanager. Is there a way to do this inside of aboutToInsert or am I
stuck adding it to my service class that has access to the enity manager?
I am trying to make it transparent that the class is being audited and
don't want to have any audited realed code in the serivice class.

I see that the event has event.getSession(). I am not familiar with an
eclipselink session and am wondering if it is this session that I can
merge the user too. If this is the case any idea's how?
Re: DescriptorEventAdapter merging and object [message #382756 is a reply to message #382751] Mon, 20 October 2008 12:28 Go to previous message
Douglas Hammond is currently offline Douglas Hammond
Messages: 8
Registered: July 2009
Junior Member
I believe I have it

public void aboutToInsert(DescriptorEvent event) {
User currentUser = UserUtil.getCurrentUser();
UnitOfWork uow = (UnitOfWork) event.getSession();
currentUser = (User)uow.mergeCloneWithReferences(currentUser);

Date now = new Date();
event.updateAttributeWithObject("dateUpdated", now);
event.updateAttributeWithObject("dateCreated", now);
event.updateAttributeWithObject("createdBy", currentUser);
event.updateAttributeWithObject("updatedBy", currentUser);
}

This seems to do it.
Previous Topic:Test works under JTA but not JPA transactions
Next Topic:QueryRedirector problem (Bug/JPA)
Goto Forum:
  


Current Time: Sun Oct 26 04:24:53 GMT 2014

Powered by FUDForum. Page generated in 0.92981 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software