FEATURE: Disable overwriting generated properties at transaction level#2943
FEATURE: Disable overwriting generated properties at transaction level#2943rPraml wants to merge 1 commit into
Conversation
2ff97fc to
effc0da
Compare
|
I like the feature. When I first read it I expect the opposite meaning for I'll ponder this ... |
|
That depends on which side you look at it from:
I agree, after your comment, the name is not the best. I'm sure we'll find an other one
|
|
Is it allowed to toggle that switch on/off during the lifespan of the transaction or would that miserably cause problems? If it can be toggled on/off at any time then a Side note: It would be so cool if that whole generated fields thing would be extendible/configurable. For example I like |
|
Generated properties are updated during save, so it is possible to modify it at nearly any time
I like that name |
… at transaction level
1f10628 to
1c20a0a
Compare
|
Replaced by #3799 |
Adds transaction-level control over whether Ebean auto-generates values for @WhenCreated, @WhenModified, @Whocreated and @WhoModified properties. Motivation Backup/restore scenarios need to preserve the original audit timestamps and user values when re-inserting exported data. Without this, every save overwrites those fields with the current time/user. Usage try (Transaction txn = DB.beginTransaction()) { txn.setGeneratedPropertiesEnabled(false); bean.setWhenCreated(originalTimestamp); bean.setWhenModified(originalTimestamp); DB.save(bean); txn.commit(); } Behaviour - Disabled (false): generated property values are only written if the property currently has a null value. Any non-null value set on the bean is preserved. - @Version is unaffected: the version property always auto-increments regardless of this setting, preserving optimistic locking integrity. - Default is true: all existing behaviour is unchanged. Files changed - Transaction — new setGeneratedPropertiesEnabled(boolean) with javadoc - SpiTransaction — new isGeneratedPropertiesEnabled() - SpiTransactionProxy — delegates both methods - JdbcTransaction — field + implementation (default true) - NoTransaction, ImplicitReadOnlyTransaction — no-op setter, true getter - PersistRequestBean — onInsertGeneratedProperties, onUpdateGeneratedProperties, onFailedUpdateUndoGeneratedProperties all gate on isGeneratedPropertiesEnabled() - TestGeneratedProperties — 3 new tests covering insert-preserves, insert-null-still-filled, and update-preserves Supersedes PR #2943 — same feature, renamed from setOverwriteGeneratedProperties to setGeneratedPropertiesEnabled for a clearer, positive-sense API. Co-authored-by: robin.bygrave <robin.bygrave@eroad.com>
We want to backup & restore some data by exporting it to JSON. For this use case we need to preserve
This PR allows to disable the update of these properties for a particular transaction