Home >Java >javaTutorial >How Can I Map JPA Entity Fields with Database Reserved Words?

How Can I Map JPA Entity Fields with Database Reserved Words?

Linda Hamilton
Linda HamiltonOriginal
2024-12-02 14:33:16755browse

How Can I Map JPA Entity Fields with Database Reserved Words?

Mapping Reserved Words as Entity Fields in JPA

JPA's use of SQL can conflict with reserved words in database dialects. To address this issue, let's explore how to map an entity field with a reserved word while avoiding the common "use your own dialect" solution.

Hibernate's Approach

Hibernate allows you to escape reserved words within backticks (`). For JPA 1.0, use:

@Column(name="`open`")

For JPA 2.0 and later, the syntax is:

@Column(name="\"open\"")

References

  • [Hibernate Reference Guide](https://docs.jboss.org/hibernate/stable/orm/reference/en/html_single/#d0e3171)
  • [5.4. SQL Quoted Identifiers](https://docs.jboss.org/hibernate/stable/orm/reference/en-US/html/dialect-options.html#d0e3171)
  • [JPA 2.0 Specification](https://docs.oracle.com/javaee/7/api/javax/persistence/Column.html#name())
  • [2.13 Naming of Database Objects](https://docs.oracle.com/javaee/7/api/javax/persistence/Table.html#name())

Additional Resources

  • [Hibernate, MySQL, and "Repeat" Table](https://stackoverflow.com/questions/18211310/hibernate-mysql-and-table-named-repeat-strange-behavior)

The above is the detailed content of How Can I Map JPA Entity Fields with Database Reserved Words?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn