liveBook · Manning

Delimited identifier

As explained in Java Persistence with Spring Data and Hibernate epub

A delimited identifier is an SQL identifier enclosed by the database system's identifier delimiters to permit otherwise special names or preserve case.

A delimited identifier encloses an SQL table or column name in database-specific identifier delimiters. It permits reserved names such as USER and can preserve otherwise significant naming behavior. section 5.3.1

Hibernate and JPA provide several quoting strategies:

  • Enable hibernate.auto_quote_keyword=true so the configured dialect automatically quotes recognized reserved keywords. section 5.3.1
  • Use Hibernate backticks in a mapping, such as @Table(name = "`USER`"). section 5.3.1
  • Use escaped double quotes, such as @Table(name = "\"USER\"")", for the JPA 2.0 delimited-identifier form. section 5.3.1
  • Declare <delimited-identifiers/> in orm.xml to enforce quoting for every SQL identifier. section 5.3.1

Mapping a reserved table name

@Entity @Table(name = "\"USER\"") public class User { // ... } Hibernate translates the mapping to the dialect's native delimiter, producing [USER] for Microsoft SQL Server, `USER` for MySQL, or "USER" for H2. section 5.3.1

@Table(name = "\"USER\"")

Inspect the JPA-compliant mapping syntax for quoting a reserved table name. section 5.3.1

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Compares automatic, manual, and global quoting, but stops short of detailed database identifier semantics.
Examples
Uses USER mappings with Hibernate backticks, JPA double quotes, dialect-specific SQL, and orm.xml global defaults.
What it assumes
Assumes familiarity with ORM mappings, persistence-unit properties, and database dialects.
What you can do after
Configure automatic or explicit identifier quoting and select a portable mapping syntax for reserved names.
How it connects
Connects identifier quoting with Hibernate, JPA, Spring Data JPA, database dialects, and reserved keywords.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.