Skip to content

Add Transaction.setGeneratedPropertiesEnabled(boolean)#3799

Merged
rbygrave merged 1 commit into
masterfrom
feature/generated-properties-enabled
Jun 26, 2026
Merged

Add Transaction.setGeneratedPropertiesEnabled(boolean)#3799
rbygrave merged 1 commit into
masterfrom
feature/generated-properties-enabled

Conversation

@rbygrave

@rbygrave rbygrave commented Jun 26, 2026

Copy link
Copy Markdown
Member

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.

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.
@rbygrave

Copy link
Copy Markdown
Member Author

This PR replaces #2943

@rbygrave rbygrave merged commit 97bd0e1 into master Jun 26, 2026
1 check passed
@rbygrave rbygrave deleted the feature/generated-properties-enabled branch June 26, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants