| preUpdateWithChanges [message #515972] |
Mon, 22 February 2010 05:54  |
Tom Eugelink Messages: 801 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 #518019 is a reply to message #515972] |
Tue, 02 March 2010 14:03   |
James Sutherland Messages: 1844 Registered: July 2009 |
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
|
|
|
|
|
| Re: preUpdateWithChanges [message #518047 is a reply to message #518038] |
Tue, 02 March 2010 15:40  |
Tom Eugelink Messages: 801 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
|
|
|
Powered by
FUDForum. Page generated in 0.01614 seconds