DescriptorEventAdapter merging and object [message #382751] |
Sun, 19 October 2008 21:10  |
Eclipse User |
|
|
|
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 08:28  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.05801 seconds