SQL Error: 1064, SQLState: 42000 while creating new entity
desc
is a mysql reserve word.Check
Solution:
Do
@Column(name="[desc]")
^ ^
Add square brackets [] .
OR
Change the name of column
Source
You can also use square brackets or double quotes to escape column name.
@Column(name="[desc]")
private String townDesc;
or
@Column(name="\"desc\"")
private String townDesc;
The error messages states:
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 'desc, name) values (2, 'Test town desc.', 'Test town')' at line 1
The problem is in the generated query, due to the usage of desc
since it's a reserved word in MySQL.
Possible solutions:
- Change the name of your column to
description
. Do similar withname
. - Change the configuration in MySQL to support these kind of names for columns in queries.
Change the name of the column in the fields to append ` character (referenced from Creating field with reserved word name with JPA):
@Column(name="`desc`")
IMO while option 3 is a quick and dirty solution, I find option 1 as the best solution for future usage of the database.