How to map an entity field whose name is a reserved word in JPA

前端 未结 7 1674
陌清茗
陌清茗 2020-11-22 12:35
@Column(name=\"open\")

Using sqlserver dialect with hibernate.

[SchemaUpdate] Unsuccessful: create table auth_session (id numeric(1         


        
7条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 13:03

    Manually escaping the reserved keywords

    If you are using JPA, you can escape with double quotes:

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

    If you're using Hibernate native API, then you can escape them using backticks:

    @Column(name = "`open`")
    

    Automatically escaping reserved keywords

    If you want to automatically escape reserved keywords, you can set to true the Hibernate-specific hibernate.globally_quoted_identifiers configuration property:

    
    

    Yaml format

    spring:
      jpa:
        properties:
          hibernate:
            globally_quoted_identifiers: true
    

    For more details, check out this article.

提交回复
热议问题