Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,44 @@
* Specifies that the annotated field of property is a generated <em>creation timestamp</em>.
* The timestamp is generated just once, when an entity instance is inserted in the database.
* <p>
* By default, the timestamp is generated by {@linkplain java.time.Clock#instant() in memory},
* By default, the timestamp is generated by {@linkplain java.time.Clock#instant in memory},
* but this may be changed by explicitly specifying the {@link #source}.
* Otherwise, this annotation is a synonym for
* {@link CurrentTimestamp @CurrentTimestamp(timing=INSERT,source=VM)}.
*
* @author Gunnar Morling
* <p>
* The annotated property may be of any one of the following types:
* {@link java.util.Date},
* {@link java.util.Calendar},
* {@link java.sql.Date},
* {@link java.sql.Time},
* {@link java.sql.Timestamp},
* {@link java.time.Instant},
* {@link java.time.LocalDate},
* {@link java.time.LocalDateTime},
* {@link java.time.LocalTime},
* {@link java.time.MonthDay},
* {@link java.time.OffsetDateTime},
* {@link java.time.OffsetTime},
* {@link java.time.Year},
* {@link java.time.YearMonth}, or
* {@link java.time.ZonedDateTime}.
* <p>
* A field annotated {@code @CreationTimestamp} may not be directly set by the application
* program.
*
* @see CurrentTimestamp
* @see UpdateTimestamp
*
* @author Gunnar Morling
*/
@ValueGenerationType(generatedBy = CurrentTimestampGeneration.class)
@Retention(RUNTIME)
@Target({ FIELD, METHOD })
public @interface CreationTimestamp {
/**
* Specifies how the timestamp is generated. By default, it is generated
* in memory, which saves a round trip to the database.
* in memory, which might save a round trip to the database, depending on
* the capabilities of the database and JDBC driver.
*/
SourceType source() default SourceType.VM;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@

/**
* Specifies that the annotated field of property is a generated timestamp,
* and also specifies the {@linkplain #event() timing} of the timestamp
* and also specifies the {@linkplain #event timing} of the timestamp
* generation, and whether it is generated in Java or by the database:
* <ul>
* <li>{@link SourceType#VM source = VM} indicates that the virtual machine
* {@linkplain java.time.Clock#instant() current instant}
* is used, and
* {@linkplain java.time.Clock#instant current instant} is used, and
* <li>{@link SourceType#DB source = DB} indicates that the database
* {@code current_timestamp} function should be used.
* </ul>
* <p>
* By default, the timestamp is generated by the database, which requires
* an extra round trip to the database to fetch the generated value.
* By default, the timestamp is generated by the database, which might
* require an extra round trip to the database to fetch the generated
* value, depending on the capabilities of the
* {@linkplain org.hibernate.dialect.Dialect#supportsInsertReturning database} and
* {@linkplain org.hibernate.dialect.Dialect#supportsInsertReturningGeneratedKeys driver}.
* <p>
* This annotation may be used in combination with the JPA-defined
* {@link jakarta.persistence.Version} annotation.
Expand All @@ -51,6 +53,9 @@
* {@link java.time.Year},
* {@link java.time.YearMonth}, or
* {@link java.time.ZonedDateTime}.
* <p>
* A field annotated {@code @CurrentTimestamp} may not be directly set
* by the application program.
*
* @see UpdateTimestamp
* @see CreationTimestamp
Expand All @@ -74,7 +79,10 @@

/**
* Specifies how the timestamp is generated. By default, it is generated
* by the database, and fetched using a subsequent {@code select} statement.
* by the database. Depending on the capabilities of the database and JDBC
* driver, this might require that the value be fetched using a subsequent
* {@code select} statement. Setting {@code source = VM} guarantees that
* this additional {@code select} never occurs.
*/
SourceType source() default SourceType.DB;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Identifies a field of an entity that holds a tenant id
* in discriminator-based multitenancy.
* Identifies a field of an entity that holds a tenant id in discriminator-based multitenancy.
* <p>
* A field annotated {@code @TenantId} is automatically set to the
* {@linkplain org.hibernate.SharedSessionContract#getTenantIdentifierValue current tenant id}
* when the entity is first made persistent. The {@code @TenantId} field may not be directly
* set by the application program.
* <p>
* If a {@code @TenantId} field is also annotated {@link jakarta.persistence.Id @Id}, it forms
* part of the composite primary key of the of an entity.
*
* @see org.hibernate.SharedSessionContract#getTenantIdentifierValue
* @see org.hibernate.context.spi.CurrentTenantIdentifierResolver
*
* @since 6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,33 @@
* Specifies that the annotated field of property is a generated <em>update timestamp.</em>
* The timestamp is regenerated every time an entity instance is updated in the database.
* <p>
* By default, the timestamp is generated {@linkplain java.time.Clock#instant() in memory},
* By default, the timestamp is generated {@linkplain java.time.Clock#instant in memory},
* but this may be changed by explicitly specifying the {@link #source}.
* Otherwise, this annotation is a synonym for
* {@link CurrentTimestamp @CurrentTimestamp(source=VM)}.
* <p>
* The annotated property may be of any one of the following types:
* {@link java.util.Date},
* {@link java.util.Calendar},
* {@link java.sql.Date},
* {@link java.sql.Time},
* {@link java.sql.Timestamp},
* {@link java.time.Instant},
* {@link java.time.LocalDate},
* {@link java.time.LocalDateTime},
* {@link java.time.LocalTime},
* {@link java.time.MonthDay},
* {@link java.time.OffsetDateTime},
* {@link java.time.OffsetTime},
* {@link java.time.Year},
* {@link java.time.YearMonth}, or
* {@link java.time.ZonedDateTime}.
* <p>
* A field annotated {@code @UpdateTimestamp} may not be directly set by the application
* program.
*
* @see CurrentTimestamp
* @see CreationTimestamp
*
* @author Gunnar Morling
*/
Expand All @@ -32,7 +53,8 @@
public @interface UpdateTimestamp {
/**
* Specifies how the timestamp is generated. By default, it is generated
* in memory, which saves a round trip to the database.
* in memory, which might save a round trip to the database, depending on
* the capabilities of the database and JDBC driver.
*/
SourceType source() default SourceType.VM;
}
Loading