8

I have used in my java DAO class which contains Space in between LANG PREF

 @Column(name = "LANG PREF")
  private String langprefid;

Once my java class runs, I am getting

org.hibernate.exception.SQLGrammarException: Incorrect syntax near the keyword 'as'.

Can anyone help me regarding this problem?

1
  • You should rather change the name of the column itself. It's just bad practice to have spaces in column names.
    – saran3h
    Apr 13, 2020 at 11:30

3 Answers 3

16

Manually escaping the reserved keywords

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

@Column(name = "`LANG PREF`")

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

@Column(name = "\"LANG PREF\"")

Automatically escaping reserved keywords

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

<property
    name="hibernate.globally_quoted_identifiers"
    value=true"
/>
0
0

Change your Column name to LANG_PREF then use

@Column(name = "LANG_PREF")
  private String langprefid;
0

You can change your code to

import javax.persistence.Column;
@Column(name = "LANG_PREF")
private String langprefid;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.