Class ChangelogSupplier<T>

java.lang.Object
org.hibernate.audit.spi.ChangelogSupplier<T>
Type Parameters:
T - the type of the changeset identifier (the @ChangesetId property type)
All Implemented Interfaces:
ChangesetIdentifierSupplier<T>

public class ChangelogSupplier<T> extends Object implements ChangesetIdentifierSupplier<T>
A built-in ChangesetIdentifierSupplier that persists a user-defined changelog entity and returns the @Changelog.ChangesetId property value as the changeset id for audit rows.

An optional ChangesetListener callback can be configured for populating custom fields.

Since:
7.4
  • Constructor Details

    • ChangelogSupplier

      public ChangelogSupplier(Class<?> changelogClass, String changesetIdProperty, String timestampProperty, @Nullable String modifiedEntitiesProperty, @Nullable ChangesetListener listener)
      Parameters:
      changelogClass - the changelog entity class
      changesetIdProperty - the name of the @ChangesetId property
      timestampProperty - the name of the @Timestamp property
      modifiedEntitiesProperty - the name of the @ModifiedEntities property, or null if entity change tracking is not configured
      listener - optional callback for populating custom fields
  • Method Details

    • getChangelogClass

      public Class<?> getChangelogClass()
      The changelog entity class.
    • getChangesetIdProperty

      public String getChangesetIdProperty()
      The name of the @Changeset property.
    • getTimestampProperty

      public String getTimestampProperty()
      The name of the @Timestamp property.
    • getListener

      @Nullable public ChangesetListener getListener()
      The configured changeset listener, or null.
    • getModifiedEntitiesProperty

      @Nullable public String getModifiedEntitiesProperty()
      The name of the @ModifiedEntities property, or null if entity change tracking is not configured.
    • generateIdentifier

      public T generateIdentifier(SharedSessionContract session)
      Description copied from interface: ChangesetIdentifierSupplier
      Called once per transaction to obtain the changeset identifier
      Specified by:
      generateIdentifier in interface ChangesetIdentifierSupplier<T>
      Parameters:
      session - the current session
      Returns:
      the changeset identifier
    • generateContext

      public ChangelogSupplier.ChangesetContext<T> generateContext(SharedSessionContract session)
      Generate the complete changelog context for the current transaction.

      This persists the configured Changelog entity, reads its changeset identifier, and returns both values together with the child session which owns deferred changelog collection work. Graph queue audit execution captures this context directly and passes the identifier into its bind plans, avoiding the legacy action-queue callback path.

      Parameters:
      session - the session requiring a changeset identifier
      Returns:
      the generated changeset context
    • registerLegacyContext

      public void registerLegacyContext(SharedSessionContractImplementor sessionImpl, ChangelogSupplier.ChangesetContext<?> context)
      Register the generated context with the legacy audit infrastructure.

      This is intentionally limited to the legacy queue. Graph queue audit execution obtains the same context from the session and does not rely on ActionQueue.setAuditChangesetContext(Object, Session).

      Parameters:
      sessionImpl - the session which owns the transaction
      context - the generated changeset context
    • resolve

      @Nullable public static ChangelogSupplier<?> resolve(ServiceRegistry registry)
      Resolve the ChangelogSupplier from the given service registry, or return null if no @Changelog is configured.