Skip to content

Commit d6e1c9b

Browse files
committed
add an example use of hibernate.type.preferred_instant_jdbc_type
1 parent d784d6a commit d6e1c9b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

documentation/src/main/asciidoc/introduction/Mapping.adoc

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ Here we summarize the ones we've just seen in the second half of this chapter, a
828828
| `@Collate` | Specify a collation for a column
829829
|===
830830

831-
In addition, there are some configuration properties which have a _global_ affect on how basic types map to SQL column types:
831+
In addition, there are link:{doc-javadoc-url}org/hibernate/cfg/MappingSettings.html[some configuration properties] which have a _global_ affect on how basic types map to SQL column types:
832832

833833
.Type mapping settings
834834
[%autowidth.stretch]
@@ -841,9 +841,25 @@ In addition, there are some configuration properties which have a _global_ affec
841841
| `hibernate.type.preferred_duration_jdbc_type` | Specify the default SQL column type for mapping `Duration`
842842
| `hibernate.type.preferred_instant_jdbc_type` | Specify the default SQL column type for mapping `Instant`
843843
| `hibernate.timezone.default_storage` | Specify the default strategy for storing time zone information
844-
| `` |
845844
|===
846845

846+
For example, if we wanted to store an `Instant` using `timestamp with time zone` (called `timestamp` on MySQL, and `datetimeoffset` on SQL Server) instead of `timestamp` (`datetime` on MySQL, `datetime2` on SQL Server), then we could annotated every field of type `Instant`:
847+
848+
[source,java]
849+
----
850+
@JdbcTypeCode(SqlTypes.TIMESTAMP_WITH_TIMEZONE)
851+
Instant instant;
852+
----
853+
854+
Alternatively, we could affect every field of type `Instant` with the property `hibernate.type.preferred_instant_jdbc_type`:
855+
856+
857+
[source,java]
858+
----
859+
config.setProperty(MappingSettings.PREFERRED_INSTANT_JDBC_TYPE, SqlTypes.TIMESTAMP_WITH_TIMEZONE);
860+
----
861+
862+
847863
[TIP]
848864
====
849865
These are _global_ settings and thus quite clumsy.
@@ -863,7 +879,7 @@ Thus, the attribute is a sort of "derived" value.
863879
|===
864880
| Annotation | Purpose
865881

866-
| `@Formula` | Map an attribute to a SQL formula
882+
| link:{doc-javadoc-url}org/hibernate/annotations/Formula.html[`@Formula`] | Map an attribute to a SQL formula
867883
| `@JoinFormula` | Map an association to a SQL formula
868884
| `@DiscriminatorFormula` | Use a SQL formula as the discriminator in <<mapping-inheritance,single table inheritance>>.
869885
|===
@@ -887,6 +903,8 @@ class Order {
887903
}
888904
----
889905

906+
The formula is evaluated every time the entity is read from the database.
907+
890908
[[derived-identity]]
891909
=== Derived Identity
892910

0 commit comments

Comments
 (0)