improve section on versions

This commit is contained in:
Gavin 2023-05-18 11:20:56 +02:00
parent bb1f5bf8e3
commit 15422ea13b
1 changed files with 4 additions and 2 deletions

View File

@ -448,7 +448,7 @@ Book book = session.find(Book.class, new BookId(isbn, printing));
=== Version attributes === Version attributes
An entity may have an attribute which is used by Hibernate for optimistic lock checking. An entity may have an attribute which is used by Hibernate for optimistic lock checking.
A version attribute is usually of type `Integer` or `LocalDateTime`, though several other types are also allowed. A version attribute is usually of type `Integer`, `Short`, `Long`, `LocalDateTime`, `OffsetDateTime`, `ZonedDateTime`, or `Instant`.
[source,java] [source,java]
---- ----
@ -456,7 +456,7 @@ A version attribute is usually of type `Integer` or `LocalDateTime`, though seve
LocalDateTime lastUpdated; LocalDateTime lastUpdated;
---- ----
The `@Id` and `@Version` attributes we've already seen are just specialized examples of _basic attributes_. Version attributes are automatically assigned by Hibernate when an entity is made persistent, and automatically incremented or updated each time the entity is updated.
[TIP] [TIP]
// .Optimistic locking in Hibernate // .Optimistic locking in Hibernate
@ -466,6 +466,8 @@ The `@OptimisticLocking` annotation lets us specify that optimistic locks should
And the `@OptimisticLock` annotation lets us selectively exclude certain fields from optimistic locking. And the `@OptimisticLock` annotation lets us selectively exclude certain fields from optimistic locking.
==== ====
The `@Id` and `@Version` attributes we've already seen are just specialized examples of _basic attributes_.
[[natural-id-attributes]] [[natural-id-attributes]]
=== Natural id attributes === Natural id attributes