-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
HHH-20214 Full @Audited entities read/write support in core
#12191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
hibernate-core/src/main/java/org/hibernate/annotations/RevisionEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.annotations; | ||
|
|
||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import org.hibernate.Incubating; | ||
| import org.hibernate.audit.RevisionListener; | ||
|
|
||
| import static java.lang.annotation.ElementType.FIELD; | ||
| import static java.lang.annotation.ElementType.METHOD; | ||
| import static java.lang.annotation.ElementType.TYPE; | ||
| import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
|
||
| /** | ||
| * Marks an entity as the revision entity for audit logging. | ||
| * The annotated class must also be annotated | ||
| * {@link jakarta.persistence.Entity @Entity} and must have: | ||
| * <ul> | ||
| * <li>a field annotated with {@link TransactionId} (typically | ||
| * the {@code @Id} with {@code @GeneratedValue})</li> | ||
| * <li>a field annotated with {@link Timestamp}</li> | ||
| * </ul> | ||
| * <p> | ||
| * The revision entity is responsible for initializing its own | ||
| * {@link Timestamp @Timestamp} field, for example, via a field | ||
| * initializer, in the constructor, or in a | ||
| * {@link org.hibernate.audit.RevisionListener}. | ||
| * <p> | ||
| * When a class annotated with {@code @RevisionEntity} is found | ||
| * in the domain model, it is automatically configured as the | ||
| * {@link org.hibernate.temporal.spi.TransactionIdentifierSupplier}, | ||
| * and no {@code hibernate.temporal.transaction_id_supplier} setting | ||
| * is required. | ||
| * <p> | ||
| * Only one entity may be annotated with {@code @RevisionEntity}. | ||
| * | ||
| * @see Audited | ||
| * @see TransactionId | ||
| * @see Timestamp | ||
| * @see RevisionListener | ||
| * @since 7.4 | ||
| */ | ||
| @Documented | ||
| @Incubating | ||
| @Retention(RUNTIME) | ||
| @Target(TYPE) | ||
| public @interface RevisionEntity { | ||
| /** | ||
| * An optional {@link RevisionListener} implementation that | ||
| * will be called after the revision entity is created, to | ||
| * populate custom fields (e.g. user, comment). | ||
| */ | ||
| Class<? extends RevisionListener> listener() default RevisionListener.class; | ||
|
|
||
| /** | ||
| * Marks the property that holds the transaction identifier | ||
| * in a {@link RevisionEntity @RevisionEntity}. This should | ||
| * typically be the auto-generated primary key | ||
| * ({@code @Id @GeneratedValue}). | ||
| * <p> | ||
| * The value is set by the persistence layer when the | ||
| * revision entity is inserted. | ||
| * | ||
| * @see RevisionEntity | ||
| * @since 7.4 | ||
| */ | ||
| @Documented | ||
| @Retention(RUNTIME) | ||
| @Target({ METHOD, FIELD }) | ||
| @interface TransactionId { | ||
| } | ||
|
|
||
| /** | ||
| * Marks the property that holds the revision timestamp in a | ||
| * {@link RevisionEntity @RevisionEntity}. The value must be | ||
| * initialized by the revision entity itself, for example, | ||
| * via a field initializer, in the constructor, or in a | ||
| * {@link org.hibernate.audit.RevisionListener}. | ||
| * | ||
| * @see RevisionEntity | ||
| * @since 7.4 | ||
| */ | ||
| @Documented | ||
| @Retention(RUNTIME) | ||
| @Target({ METHOD, FIELD }) | ||
| @interface Timestamp { | ||
| } | ||
|
|
||
| /** | ||
| * Marks a {@code Set<String>} property on a | ||
| * {@link RevisionEntity @RevisionEntity} that holds the | ||
| * names of entity types modified in each revision. The | ||
| * property is typically mapped as an | ||
| * {@code @ElementCollection}. | ||
| * <p> | ||
| * When this annotation is present on a revision entity, | ||
| * cross-type revision queries are automatically enabled | ||
| * via {@link org.hibernate.audit.AuditLog}. | ||
| * | ||
| * @see RevisionEntity | ||
| * @since 7.4 | ||
| */ | ||
| @Documented | ||
| @Retention(RUNTIME) | ||
| @Target({ METHOD, FIELD }) | ||
| @interface ModifiedEntities { | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
hibernate-core/src/main/java/org/hibernate/audit/AuditEntry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.audit; | ||
|
|
||
|
|
||
| /** | ||
| * A tuple representing an entity at a specific revision in | ||
| * the audit history. | ||
| * <p> | ||
| * The {@link #revision} field is: | ||
| * <ul> | ||
| * <li>the revision entity instance (e.g. {@link DefaultRevisionEntity}), if one is configured | ||
| * <li>the plain transaction identifier (e.g. {@code Instant}, {@code Integer}) otherwise</li> | ||
| * </ul> | ||
| * | ||
| * @param entity the entity snapshot at this revision | ||
| * @param revision the revision entity (if configured) or transaction identifier | ||
| * @param modificationType the type of modification (ADD/MOD/DEL) | ||
| * @param <T> the entity type | ||
| * @author Marco Belladelli | ||
| * @since 7.4 | ||
| */ | ||
| public record AuditEntry<T>(T entity, Object revision, ModificationType modificationType) { | ||
| } |
23 changes: 23 additions & 0 deletions
23
hibernate-core/src/main/java/org/hibernate/audit/AuditException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.audit; | ||
|
|
||
| import org.hibernate.HibernateException; | ||
|
|
||
| /** | ||
| * Indicates a problem related to audit functionality. | ||
| * | ||
| * @author Marco Belladelli | ||
| * @since 7.4 | ||
| */ | ||
| public class AuditException extends HibernateException { | ||
| public AuditException(String message) { | ||
| super( message ); | ||
| } | ||
|
|
||
| public AuditException(String message, Throwable cause) { | ||
| super( message, cause ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.