From d5e829d26c1a7f3689ded4ad66b22d9f4ad97709 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Sun, 10 Nov 2024 09:33:17 +0100 Subject: [PATCH] add section on quoted identifiers to doc Signed-off-by: Gavin King --- .../asciidoc/introduction/Configuration.adoc | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/documentation/src/main/asciidoc/introduction/Configuration.adoc b/documentation/src/main/asciidoc/introduction/Configuration.adoc index 42c0643e64..5b344ca9f4 100644 --- a/documentation/src/main/asciidoc/introduction/Configuration.adoc +++ b/documentation/src/main/asciidoc/introduction/Configuration.adoc @@ -494,6 +494,32 @@ Writing your own `PhysicalNamingStrategy` and/or `ImplicitNamingStrategy` is an We'll have more to say about them in <>. ==== +[[quoted-identifiers]] +=== Quoting SQL identifiers + +By default, Hibernate never quotes SQL table and column names in generated SQL. +This behavior is usually much more convenient, especially when working with a legacy schema, since unquoted identifiers aren't case-sensitive, and so Hibernate doesn't need to know or care whether a column is named `NAME`, `name`, or `Name` on the database side. + +The following settings enable automatic quoting: + +.Settings for identifier quoting +[%breakable,cols="35,~"] +|=== +| Configuration property name | Purpose + +| `hibernate.auto_quote_keyword` | Automatically quote any identifier which is a SQL keyword +| `hibernate.globally_quoted_identifiers` | Automatically quote every identifier +|=== + +Note that `hibernate.globally_quoted_identifiers` is a synonym for `` in <>. +We don't recommend the use of global identifier quoting, and in fact these settings are rarely used. + +[TIP] +==== +A better alternative is to explicitly quote table and column names where necessary, by writing `@Table(name="\"View\")` or `@Column(name="\"number\"")`. +Since that's kinda ugly, Hibernate lets us use a backtick as the quote character instead of the double quote. +==== + [[nationalized-chars]] === Nationalized character data in SQL Server