为了账号安全,请及时绑定邮箱和手机立即绑定

hibernate报Could not execute JDBC batch update异常,麻烦各位大神解答

public static void main(String[] args) {
  Session session=null;
  Transaction tx=null;
  
  
  session=HibernateSessionFactory.getSession();
  tx=session.beginTransaction();
  Grade g=new Grade("Java1班", "Java软件开发1班");
  Student s1=new Student("伍书行", "男");
  Student s2=new Student("孔德乐", "男");
  s1.setGrade(g);
  s2.setGrade(g);
  
  session.save(s1);
  session.save(s2);
  
  tx.commit();
  HibernateSessionFactory.closeSession();
  

 }

Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
 at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
 at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
 at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
 at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
 at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
 at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
 at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
 at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
 at Test.main(Test.java:31)
Caused by: java.sql.BatchUpdateException: 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 '-ONE2MANY.student (gid, sname, sex, sid) values (1, '孔德乐', '男', 2)' at line 1
 at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2054)
 at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1467)
 at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
 at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
 ... 8 more
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 '-ONE2MANY.student (gid, sname, sex, sid) values (1, '孔德乐', '男', 2)' at line 1
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
 at com.mysql.jdbc.Util.getInstance(Util.java:386)
 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
 at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
 at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
 at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
 at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2006)
 ... 11 more

正在回答

1 回答

这个的意思是说你的SQL语法有错误,你参考CSDN这个博客地址看看自己的配置,博客网址http://blog.csdn.net/derpvailzhangfan/article/details/2332795

0 回复 有任何疑惑可以回复我~
#1

慕妹6361977 提问者

多谢解答
2018-03-14 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Hibernate初探之一对多映射
  • 参与学习       42171    人
  • 解答问题       295    个

Hibernate中一对多关联映射配置,以及cascade和inverse属性作用

进入课程

hibernate报Could not execute JDBC batch update异常,麻烦各位大神解答

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信