Hibernate - You have an error in your SQL syntax

If you see following error, it could just be, that you use one of the MySQL reserved words.

ERROR 1064 (42000) at line: You have an error in your SQL syntax

Hibernate Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@Entity
@Table(name = "user")
@NamedQuery(name = "getAllUsers", query = "SELECT u FROM User u")
public class User {

/** The id. */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

/** /The user name. */
private String name;

/** Creation Date. */
private Date create;
}

The example contains a variable called “create” which is reserved by MySQL and can not be used.
Please be aware that MySQL have a lot of those:

Reserved Words
ACCESSIBLEADDALL
ALTERANALYZEAND
ASASCASENSITIVE
BEFOREBETWEENBIGINT
BINARYBLOBBOTH
BYCALLCASCADE
CASECHANGECHAR
CHARACTERCHECKCOLLATE
COLUMNCONDITIONCONSTRAINT
CONTINUECONVERTCREATE
CROSSCURRENT_DATECURRENT_TIME
CURRENT_TIMESTAMPCURRENT_USERCURSOR
DATABASEDATABASESDAY_HOUR
DAY_MICROSECONDDAY_MINUTEDAY_SECOND
DECDECIMALDECLARE
DEFAULTDELAYEDDELETE
DESCDESCRIBEDETERMINISTIC
DISTINCTDISTINCTROWDIV
DOUBLEDROPDUAL
EACHELSEELSEIF
ENCLOSEDESCAPEDEXISTS
EXITEXPLAINFALSE
FETCHFLOATFLOAT4
FLOAT8FORFORCE
FOREIGNFROMFULLTEXT
GRANTGROUPHAVING
HIGH_PRIORITYHOUR_MICROSECONDHOUR_MINUTE
HOUR_SECONDIFIGNORE
ININDEXINFILE
INNERINOUTINSENSITIVE
INSERTINTINT1
INT2INT3INT4
INT8INTEGERINTERVAL
INTOISITERATE
JOINKEYKEYS
KILLLEADINGLEAVE
LEFTLIKELIMIT
LINEARLINESLOAD
LOCALTIMELOCALTIMESTAMPLOCK
LONGLONGBLOBLONGTEXT
LOOPLOW_PRIORITYMASTER_SSL_VERIFY_SERVER_CERT
MATCHMAXVALUEMEDIUMBLOB
MEDIUMINTMEDIUMTEXTMIDDLEINT
MINUTE_MICROSECONDMINUTE_SECONDMOD
MODIFIESNATURALNOT
NO_WRITE_TO_BINLOGNULLNUMERIC
ONOPTIMIZEOPTION
OPTIONALLYORORDER
OUTOUTEROUTFILE
PRECISIONPRIMARYPROCEDURE
PURGERANGEREAD
READSREAD_WRITEREAL
REFERENCESREGEXPRELEASE
RENAMEREPEATREPLACE
REQUIRERESIGNALRESTRICT
RETURNREVOKERIGHT
RLIKESCHEMASCHEMAS
SECOND_MICROSECONDSELECTSENSITIVE
SEPARATORSETSHOW
SIGNALSMALLINTSPATIAL
SPECIFICSQLSQLEXCEPTION
SQLSTATESQLWARNINGSQL_BIG_RESULT
SQL_CALC_FOUND_ROWSSQL_SMALL_RESULTSSL
STARTINGSTRAIGHT_JOINTABLE
TERMINATEDTHENTINYBLOB
TINYINTTINYTEXTTO
TRAILINGTRIGGERTRUE
UNDOUNIONUNIQUE
UNLOCKUNSIGNEDUPDATE
USAGEUSEUSING
UTC_DATEUTC_TIMEUTC_TIMESTAMP
VALUESVARBINARYVARCHAR
VARCHARACTERVARYINGWHEN
WHEREWHILEWITH
WRITEXORYEAR_MONTH
ZEROFILL