Spring JPA-Hibernate报错:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an er

Hibernate:

alter table emp.customer 
   add column desc varchar(255)

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 varchar(255)’
初读Exception是我的Sql语句写的有问题,但这里使用的是Hibernate,sql语句不是我写的,怎么会出错呢,排查原因,注意到我的SQL语句,
解决方法:
其中一篇博客中写道,这个可能是属性与mysql数据库关键字重合。我马上查看我的属性,发现desc属性很有可能跟mysql关键字重合了,于是马上将实体类和数据库中的desc属性修改为descrption属性。运行,异常消失,保存成功!
总结:
这个异常卡了一下午的时间,由于自己的失误,使用了数据库的关键字作为表的字段。记录下该异常,防止在出现类似的错误。

猜你喜欢

转载自blog.csdn.net/weixin_40944832/article/details/86637793
今日推荐