markAsDirty not working? #2842
Replies: 2 comments 5 replies
-
I see this, sorry, haven't got to it yet. In short we need to mark which properties are changed and I need to explain why etc. Should get to this soon, hopefully tomorrow. Cheers, Rob. |
Beta Was this translation helpful? Give feedback.
-
BackgroundWe have per property changed state. Why? To optimise SQL UPDATE we only desire to include in the UPDATE the properties that have actually changed. For example, if an entity had 100 properties and we only changed 1 of those we don't really want to include the other 99 in the UPDATE. Another example, if an entity had 5 properties but some of those were VARCHAR(5000) we similarly only wish to include only the properties that were changed. Simply including all properties in an update is not something we want to do frequently or by default. On a per property basis we can also hold "Old Values". These are used to support ChangeLog etc. When we do a "stateless update" we don't have "Old Values" and this is ok, we just need to know and understand that. Sometimes we are either happy to or must perform a "stateless update" and when we do there are no "Old Values" (to support ChangeLog etc). With respect to setter methods / mutator methods / setting fields. What is generally happening is that Ebean enhancement is changing
We still need the detail on which property is changed.
In the absence of anything else, when using a PUTFIELD there is no interception ocuring per say and hence no recognition that the field changed and no storing of an 'Old value'. To say that differently, Ebean only creates the "Old values" on demand (via the interception that is put on the setters/mutator methods). This means that read only cases for Ebean are much cheaper than some other ORMs that instead create and hold the "Old values" regardless. I'd suggest there are 4 ways of addressing the use case of using PUTFIELD but still getting all the expected dirty state.
|
Beta Was this translation helpful? Give feedback.
-
Hello,
We are using ebean 13.1.0 and we have a large reference data set, with over 150 tables and growing. We do not want to write getters/setters for each field, even with the help of lombok. We really only write to these tables during testing or data cleanup steps. So, rather that use
myModel.setSomeField(toThisValue)
, we simply use:myModel.setSomeField = toThisValue;
Of course, this will fail to update the db with an
myModel.update()
call.So, we first call
myModel.markAsDirty()
but the update still fails.Shouldn't that trigger it to update the entire model or at least check which fields have different values and then update?
How can we use
=
instead ofsetXXX
and still get an update working as intended?Any help would be appreciated.
Thank you,
-Dwayne
Beta Was this translation helpful? Give feedback.
All reactions