Skip to content

Commit 30232c2

Browse files
committed
more info in javadoc of some generator annotations
Signed-off-by: Gavin King <[email protected]>
1 parent 68abe5a commit 30232c2

File tree

4 files changed

+74
-14
lines changed

4 files changed

+74
-14
lines changed

hibernate-core/src/main/java/org/hibernate/annotations/CreationTimestamp.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,44 @@
1717
* Specifies that the annotated field of property is a generated <em>creation timestamp</em>.
1818
* The timestamp is generated just once, when an entity instance is inserted in the database.
1919
* <p>
20-
* By default, the timestamp is generated by {@linkplain java.time.Clock#instant() in memory},
20+
* By default, the timestamp is generated by {@linkplain java.time.Clock#instant in memory},
2121
* but this may be changed by explicitly specifying the {@link #source}.
2222
* Otherwise, this annotation is a synonym for
2323
* {@link CurrentTimestamp @CurrentTimestamp(timing=INSERT,source=VM)}.
24-
*
25-
* @author Gunnar Morling
24+
* <p>
25+
* The annotated property may be of any one of the following types:
26+
* {@link java.util.Date},
27+
* {@link java.util.Calendar},
28+
* {@link java.sql.Date},
29+
* {@link java.sql.Time},
30+
* {@link java.sql.Timestamp},
31+
* {@link java.time.Instant},
32+
* {@link java.time.LocalDate},
33+
* {@link java.time.LocalDateTime},
34+
* {@link java.time.LocalTime},
35+
* {@link java.time.MonthDay},
36+
* {@link java.time.OffsetDateTime},
37+
* {@link java.time.OffsetTime},
38+
* {@link java.time.Year},
39+
* {@link java.time.YearMonth}, or
40+
* {@link java.time.ZonedDateTime}.
41+
* <p>
42+
* A field annotated {@code @CreationTimestamp} may not be directly set by the application
43+
* program.
2644
*
2745
* @see CurrentTimestamp
46+
* @see UpdateTimestamp
47+
*
48+
* @author Gunnar Morling
2849
*/
2950
@ValueGenerationType(generatedBy = CurrentTimestampGeneration.class)
3051
@Retention(RUNTIME)
3152
@Target({ FIELD, METHOD })
3253
public @interface CreationTimestamp {
3354
/**
3455
* Specifies how the timestamp is generated. By default, it is generated
35-
* in memory, which saves a round trip to the database.
56+
* in memory, which might save a round trip to the database, depending on
57+
* the capabilities of the database and JDBC driver.
3658
*/
3759
SourceType source() default SourceType.VM;
3860
}

hibernate-core/src/main/java/org/hibernate/annotations/CurrentTimestamp.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@
1919

2020
/**
2121
* Specifies that the annotated field of property is a generated timestamp,
22-
* and also specifies the {@linkplain #event() timing} of the timestamp
22+
* and also specifies the {@linkplain #event timing} of the timestamp
2323
* generation, and whether it is generated in Java or by the database:
2424
* <ul>
2525
* <li>{@link SourceType#VM source = VM} indicates that the virtual machine
26-
* {@linkplain java.time.Clock#instant() current instant}
27-
* is used, and
26+
* {@linkplain java.time.Clock#instant current instant} is used, and
2827
* <li>{@link SourceType#DB source = DB} indicates that the database
2928
* {@code current_timestamp} function should be used.
3029
* </ul>
3130
* <p>
32-
* By default, the timestamp is generated by the database, which requires
33-
* an extra round trip to the database to fetch the generated value.
31+
* By default, the timestamp is generated by the database, which might
32+
* require an extra round trip to the database to fetch the generated
33+
* value, depending on the capabilities of the
34+
* {@linkplain org.hibernate.dialect.Dialect#supportsInsertReturning database} and
35+
* {@linkplain org.hibernate.dialect.Dialect#supportsInsertReturningGeneratedKeys driver}.
3436
* <p>
3537
* This annotation may be used in combination with the JPA-defined
3638
* {@link jakarta.persistence.Version} annotation.
@@ -51,6 +53,9 @@
5153
* {@link java.time.Year},
5254
* {@link java.time.YearMonth}, or
5355
* {@link java.time.ZonedDateTime}.
56+
* <p>
57+
* A field annotated {@code @CurrentTimestamp} may not be directly set
58+
* by the application program.
5459
*
5560
* @see UpdateTimestamp
5661
* @see CreationTimestamp
@@ -74,7 +79,10 @@
7479

7580
/**
7681
* Specifies how the timestamp is generated. By default, it is generated
77-
* by the database, and fetched using a subsequent {@code select} statement.
82+
* by the database. Depending on the capabilities of the database and JDBC
83+
* driver, this might require that the value be fetched using a subsequent
84+
* {@code select} statement. Setting {@code source = VM} guarantees that
85+
* this additional {@code select} never occurs.
7886
*/
7987
SourceType source() default SourceType.DB;
8088
}

hibernate-core/src/main/java/org/hibernate/annotations/TenantId.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@
1515
import static java.lang.annotation.RetentionPolicy.RUNTIME;
1616

1717
/**
18-
* Identifies a field of an entity that holds a tenant id
19-
* in discriminator-based multitenancy.
18+
* Identifies a field of an entity that holds a tenant id in discriminator-based multitenancy.
19+
* <p>
20+
* A field annotated {@code @TenantId} is automatically set to the
21+
* {@linkplain org.hibernate.SharedSessionContract#getTenantIdentifierValue current tenant id}
22+
* when the entity is first made persistent. The {@code @TenantId} field may not be directly
23+
* set by the application program.
24+
* <p>
25+
* If a {@code @TenantId} field is also annotated {@link jakarta.persistence.Id @Id}, it forms
26+
* part of the composite primary key of the of an entity.
2027
*
28+
* @see org.hibernate.SharedSessionContract#getTenantIdentifierValue
2129
* @see org.hibernate.context.spi.CurrentTenantIdentifierResolver
2230
*
2331
* @since 6.0

hibernate-core/src/main/java/org/hibernate/annotations/UpdateTimestamp.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,33 @@
1717
* Specifies that the annotated field of property is a generated <em>update timestamp.</em>
1818
* The timestamp is regenerated every time an entity instance is updated in the database.
1919
* <p>
20-
* By default, the timestamp is generated {@linkplain java.time.Clock#instant() in memory},
20+
* By default, the timestamp is generated {@linkplain java.time.Clock#instant in memory},
2121
* but this may be changed by explicitly specifying the {@link #source}.
2222
* Otherwise, this annotation is a synonym for
2323
* {@link CurrentTimestamp @CurrentTimestamp(source=VM)}.
24+
* <p>
25+
* The annotated property may be of any one of the following types:
26+
* {@link java.util.Date},
27+
* {@link java.util.Calendar},
28+
* {@link java.sql.Date},
29+
* {@link java.sql.Time},
30+
* {@link java.sql.Timestamp},
31+
* {@link java.time.Instant},
32+
* {@link java.time.LocalDate},
33+
* {@link java.time.LocalDateTime},
34+
* {@link java.time.LocalTime},
35+
* {@link java.time.MonthDay},
36+
* {@link java.time.OffsetDateTime},
37+
* {@link java.time.OffsetTime},
38+
* {@link java.time.Year},
39+
* {@link java.time.YearMonth}, or
40+
* {@link java.time.ZonedDateTime}.
41+
* <p>
42+
* A field annotated {@code @UpdateTimestamp} may not be directly set by the application
43+
* program.
2444
*
2545
* @see CurrentTimestamp
46+
* @see CreationTimestamp
2647
*
2748
* @author Gunnar Morling
2849
*/
@@ -32,7 +53,8 @@
3253
public @interface UpdateTimestamp {
3354
/**
3455
* Specifies how the timestamp is generated. By default, it is generated
35-
* in memory, which saves a round trip to the database.
56+
* in memory, which might save a round trip to the database, depending on
57+
* the capabilities of the database and JDBC driver.
3658
*/
3759
SourceType source() default SourceType.VM;
3860
}

0 commit comments

Comments
 (0)