Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » preUpdateWithChanges
preUpdateWithChanges [message #515972] Mon, 22 February 2010 10:54 Go to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
Registered: July 2009
Senior Member
I've got master-detail relationship mapped on both sides; the parent has a list of children, the child a single reference to the parent. When a new child is added, it is added to the parent's list, but in the "real" (database) world there naturally is only a foreign key from the child to the parent.

When persisting this, the preUpdateWithChanges event is fired on the parent. This confuses me, there is nothing to update on the parent.

And Eclipselink actually does not update anything if left alone, but I use this event to set a "who'd done it" field, which results in there being something to update, and I get an update just setting the who and version field. And as a consequence I get a lot of history records containing only a changed who'd-done-it field.

Why is the preUpdateWithChanges event fired when in fact there isn't anything to write to the database?

Tom
Re: preUpdateWithChanges [message #516601 is a reply to message #515972] Wed, 24 February 2010 14:26 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
Registered: July 2009
Senior Member
Can anyone shed a light on why the preUpdateWithChanges event fires when the entity has no changes to write to the database? Is this correct?
Re: preUpdateWithChanges [message #518019 is a reply to message #515972] Tue, 02 March 2010 19:03 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The event is fired, because, as you said, there are changes at the object level.

The event object will have an ObjectChangeSet associated with it, you could check this change set to see if the only change was a OneToMany.

You could also use the aboutToUpdate event, it is only fired if the database will be updated.


James : Wiki : Book : Blog : Twitter
Re: preUpdateWithChanges [message #518033 is a reply to message #518019] Tue, 02 March 2010 20:02 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
Registered: July 2009
Senior Member
> You could also use the aboutToUpdate event, it is only fired if the
> database will be updated.

Will changes being made in the aboutToUpdate handler still be included?
Re: preUpdateWithChanges [message #518038 is a reply to message #515972] Tue, 02 March 2010 20:22 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

As long as you make the changes using the event object, they will be applied. (event.updateAttributeWithObject()).


James : Wiki : Book : Blog : Twitter
Re: preUpdateWithChanges [message #518047 is a reply to message #518038] Tue, 02 March 2010 20:40 Go to previous message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
Registered: July 2009
Senior Member
> As long as you make the changes using the event object, they will be
> applied. (event.updateAttributeWithObject()).

Ok. I'm going to try this other approach I started today first; I know which properties are "changing" properties and which ones are not, so I should be able to set a boolean myself.

Tom
Previous Topic:SequenceGenerator and schema
Next Topic:Caching Behavior for @ReadOnly Entities?
Goto Forum:
  


Current Time: Fri Apr 19 23:55:43 GMT 2024

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

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

Back to the top