亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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初探之一對多映射
  • 參與學習       42160    人
  • 解答問題       310    個

Hibernate中一對多關聯映射配置,以及cascade和inverse屬性作用

進入課程

hibernate報Could not execute JDBC batch update異常,麻煩各位大神解答

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號