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
Release: 2024-12-02 14:33:16
Original
682 people have browsed it

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`")
Copy after login

For JPA 2.0 and later, the syntax is:

@Column(name="\"open\"")
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template