报错如下:
org.springframework.dao.InvalidDataAccessResourceUsageException: Could not execute JDBC batch update; nested exception is org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
手贱,建了个表叫Check,里面有个列名叫leave ,后来查mysql的关键字发现是两个活生生的关键字啊。 这个关键字查询不会报错,调用update就报错了!
解决方法Hibernate配置取别名:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="org.model.Check" table="tcheck" catalog="hotel" dynamic-insert="true" dynamic-update="true">
<id name="checkid" type="java.lang.Integer">
<column name="checkid" />
<generator class="identity" />
</id>
<property name="sid" type="java.lang.Integer">
<column name="sid" />
</property>
<property name="checkin" type="java.util.Date">
<column name="checkin" length="10" />
</property>
<property name="checkout" type="java.util.Date">
<column name="checkout" length="10" />
</property>
<property name="checked" type="java.lang.Integer">
<column name="checked" />
</property>
<property name="late" type="java.lang.Integer">
<column name="late" />
</property>
<property name="leave" type="java.lang.Integer">
<column name="fuckleave" /> //这里取别名
</property>
<property name="day" type="java.util.Date">
<column name="day" length="10" />
</property>
<property name="about" type="java.lang.String">
<column name="about" />
</property>
<many-to-one name="staff" column="staff_sid" class="org.model.Staff" cascade="none" fetch="select" lazy="false" not-found="ignore"> </many-to-one>
</class>
</hibernate-mapping>
再把数据库里面相对应表的名字和列名改了就好了,还有,提醒:如果你这里Hibernate配置错了,会报404错误