莫名其妙的错误
一个简单类都出错,困扰我两天了;实体类:publicclassOrder{privateintid;privateintstatus;setterandgetter......
一个简单类都出错,困扰我两天了 ;
实体类:public class Order {
private int id;
private int status;
setter and getter.....
}
映像:
<class name="shopping.entity.Order">
<id column="order_id" name="id">
<generator class="native"/>
</id>
<property generated="never" lazy="false" name="status" type="integer"/>
</class>
持久化类:
public static void save(Order o){
Session session=null;
Transaction tran = null;
try{session = HibernateUtil.getSession();
tran = session.beginTransaction();
session.save(o);
tran.commit();
}catch(Exception e){e.printStackTrace();tran.rollback();
}finally{session.close();}
}
老出错,我另外写个新测试类都可以,就它出错!
这个个单向的一对多类,为了 测试把一对多的映像先删了,也出错。我写了那么多的一对多都没出错,完全不明白错在哪!困扰我两天了,求达人指点!!!
org.hibernate.exception.SQLGrammarException: could not insert: [shopping.entity.Order]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:1986)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2405)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:37)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:269)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)
省略7处错误;
Caused by: 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 (status) values (1)' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1026)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL
省略5错误
... 16 more 展开
实体类:public class Order {
private int id;
private int status;
setter and getter.....
}
映像:
<class name="shopping.entity.Order">
<id column="order_id" name="id">
<generator class="native"/>
</id>
<property generated="never" lazy="false" name="status" type="integer"/>
</class>
持久化类:
public static void save(Order o){
Session session=null;
Transaction tran = null;
try{session = HibernateUtil.getSession();
tran = session.beginTransaction();
session.save(o);
tran.commit();
}catch(Exception e){e.printStackTrace();tran.rollback();
}finally{session.close();}
}
老出错,我另外写个新测试类都可以,就它出错!
这个个单向的一对多类,为了 测试把一对多的映像先删了,也出错。我写了那么多的一对多都没出错,完全不明白错在哪!困扰我两天了,求达人指点!!!
org.hibernate.exception.SQLGrammarException: could not insert: [shopping.entity.Order]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:1986)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2405)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:37)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:269)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)
省略7处错误;
Caused by: 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 (status) values (1)' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1026)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL
省略5错误
... 16 more 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询