document @DialectOverride

This commit is contained in:
Gavin 2023-05-19 10:54:01 +02:00 committed by Gavin King
parent 47d8a63f16
commit 56ffbc104c
1 changed files with 13 additions and 0 deletions

View File

@ -221,6 +221,19 @@ However, the `@Column` annotation does lend some flexibility here:
- if a column should not be written as part of the custom `insert` statement, and has no corresponding JDBC parameter in the custom SQL, map it `@Column(insertable=false)`, or
- if a column should not be written as part of the custom `update` statement, and has no corresponding JDBC parameter in the custom SQL, map it `@Column(updatable=false)`.
[TIP]
====
If you need custom SQL, but are targeting multiple dialects of SQL, you can use the annotations defined in `DialectOverrides`.
For example, this annotation lets us override the custom `insert` statement just for PostgreSQL:
[source,java]
----
@DialectOverride.SQLInsert(dialect = PostgreSQLDialect.class,
override = @SQLInsert(sql="insert into person (name,id) values (?,gen_random_uuid())"))
----
It's even possible to override the custom SQL for specific _versions_ of a database.
====
Sometimes a custom `insert` or `update` statement assigns a value to a mapped column which is calculated when the statement is executed on the database.
For example, the value might be obtained by calling a SQL function: