How to use Space in column name with JPA and Hibernate
I used in my Java DAO class which contains a space between LANG PREF
@Column(name = "LANG PREF")
private String langprefid;
As soon as my java class starts, I get
org.hibernate.exception.SQLGrammarException: Incorrect syntax near the keyword 'as'.
Can anyone help me with this problem?
source to share
Escaping manually reserved keywords
If you are using the Hibernate native API, you can avoid them with back checkboxes:
@Column(name = "'LANG PREF'")
If you are using JPA you can avoid double quotes:
@Column(name = "\"LANG PREF\"")
Automatically escaping reserved keywords
If you want to automatically trim reserved keywords, you can set a value true
for the configuration property hibernate.globally_quoted_identifiers
specific to hibernate.globally_quoted_identifiers
:
<property
name="hibernate.globally_quoted_identifiers"
value=true"
/>
For more details, check out this article .
source to share