java - Hibernate throws SQLGrammarException -
the entity class :
@entity @table(name = "moviedetail") public class moviedetailimpl implements moviedetail { @id // primary key @column(name = "idmoviedetail") @generatedvalue(strategy = generationtype.identity) private long id; @column(name = "cast") private string cast; @column(name = "producer") private string producer; @column(name = "director") private string director; @column(name = "trailer") private url trailer; @column(name = "photo") private url photo; @column(name = "plot") private url plot; @column(name = "desc") private string desc; @column(name = "moredetails") private url moredetails; // getters/setters }
i trying persist moviedetail
entity cast
set. rest of fields null
.
hibernate throws below exception:
014-08-17 21:47:35 info transactionfactoryinitiator:62 - hhh000399: using default transaction strategy (direct jdbc transactions)
2014-08-17 21:47:35 info astquerytranslatorfactory:47 - hhh000397: using astquerytranslatorfactory
2014-08-17 21:47:36 info hibernatetransactionmanager:341 - using datasource [org.springframework.jdbc.datasource.drivermanagerdatasource@1fba434a] of hibernate sessionfactory hibernatetransactionmanager
hibernate: insert moviedetail (cast, desc, director, moredetails, photo, plot, producer, trailer) values (?, ?, ?, ?, ?, ?, ?, ?)
2014-08-17 21:47:36 warn sqlexceptionhelper:144 - sql error: 1064, sqlstate: 42000
2014-08-17 21:47:36 error sqlexceptionhelper:146 - have error in sql syntax; check manual corresponds mysql server version right syntax use near 'desc, director, moredetails, photo, plot, producer, trailer) values ('testgetall' @ line 1
2014-08-17 21:47:36 info genericapplicationcontext:873 - closing org.springframework.context.support.genericapplicationcontext@40266966: startup date [sun aug 17 21:47:34 pdt 2014]; root of context hierarchy
in 'database.properties' , have :
jdbc.dialect=org.hibernate.dialect.mysql5dialect
i using mysql community server 5.6.20. , mysql java driver version dependency defined in maven's pom.xml
<dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.28</version> </dependency>
am missing here?
you have column named desc
, , desc
reserved work in mysql (and many other databases).
you can:
- from this , this can make hibernate escape column , table names:
hibernate.globally_quoted_identifiers=true
(inpersistence.xml
, or hibernate configuration. - change name of column
- from this can escape identifier using:
@column(name="\"desc\"")
also, if not legacy database, please consider renaming.
Comments
Post a Comment