请教高手:spring +struts2+hibernate 问题
我是一个初学者,在写一个在线购物系统的生成订单时抛出异常,遇到了如下问题,查了好长时间也没解决,望哪位高手帮忙解决一下,谢谢啦
问题如下:description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not fetch initial value; bad SQL grammar [select max(id) from order]; nested exception is com.mysql.jdbc.exceptions.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 'order' at line 1
root cause
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not fetch initial value; bad SQL grammar [select max(id) from order]; nested exception is com.mysql.jdbc.exceptions.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 'order' at line 1
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:224)
org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException
root cause
com.mysql.jdbc.exceptions.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 'order' at line 1
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
com.mysql.jdbc.Connection.execSQL(Connection.java:3176)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1153)
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1266)
org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:89)
org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:45)
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:85)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId
。。。
部分代码如下:
数据库映射文件Order.hbm.xml
<?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="com.onlineshop.bean.Order" table="order">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="increment" />
</id>
<property name="orderId" type="java.lang.Integer">
<column name="orderId" not-null="true" />
</property>
<many-to-one name="cominfo" class="com.onlineshop.bean.ComInfo" fetch="select">
<column name="comid" not-null="true" />
</many-to-one>
<many-to-one name="userinfo" class="com.onlineshop.bean.User" fetch="select">
<column name="userid" not-null="true" />
</many-to-one>
<property name="number" type="java.lang.Integer">
<column name="number" not-null="true" />
</property>
<property name="address" type="java.lang.String">
<column name="address" length="128" not-null="true" />
</property>
<property name="postcode" type="java.lang.String">
<column name="postcode" length="10" not-null="true" />
</property>
<property name="orderdate" type="java.util.Date">
<column name="orderdate" length="19" not-null="true" />
</property>
<property name="status" type="java.lang.String">
<column name="status" not-null="true" />
</property>
</class>
</hibernate-mapping>
OrderDaoImpl 中生成订单的代码:
public class OrderDaoImpl extends HibernateDaoSupport implements OrderDao{
public void save(Order order){
getHibernateTemplate().saveOrUpdate(order);
}
。。。。。
}