Hibernate利用save()方法时报mysql语法错误

本文介绍了一种常见的Hibernate操作数据库时出现的问题:使用MySQL关键字作为表名导致的语法错误。通过修改表名避免了这一问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在利用hibernate的session.save()方法生成table,并插入数据时,报了如下错误


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 'ORDER (ORDER_NAME, CUSTOMER_ID) values ('aaa', 2)' at line 1

八月 07, 2017 12:05:23 下午 org.hibernate.AssertionFailure <init>

ERROR: HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: null id in n21.Order entry (don't flush the Session after an exception occurs)


检查后发现问题在标红字体那一段,然后把Order.hbm.xml中的 <class name="n21.Order" table="ORDER"> table="ORDER"改成ORDERS,看来,order是mysql的关键字啊

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值