-1

how to add boolean fields in java model class through hibernate annotations.

I am doing this and its shows me error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Like bit' at line 2

My code:

@Column(name="Like")
private boolean like;

@Column(name="Dislike")
private boolean dislike;

@Column(name="Flag")
private boolean flag;
cнŝdk
  • 31,391
  • 7
  • 56
  • 78
Aqib Bhat
  • 11
  • 6
  • 1
    You're much more likely to get useful answers if you edit your post to include the content of the error you're seeing. – DaveyDaveDave Aug 28 '18 at 06:04
  • `Like` is an SQL keyword, you can't use it as column name. – cнŝdk Aug 28 '18 at 06:44
  • ... unless you put tick marks around it, or your JPA provider does that automatically for you (seems yours doesnt have that feature) –  Aug 28 '18 at 07:47

1 Answers1

0

In fact your problem is that you used Like as a column name in your entity, so Hibernate will try to map this column to the name Like while it's a reserved keyword in SQL, that's why you got the exception:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Like bit' at line 2

What you can do here is either to use a different name of the column or escape the name.

For further details and escaping solutions you can check:

cнŝdk
  • 31,391
  • 7
  • 56
  • 78