I'm having the following Hibernate configuration:
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3336/db
org.hibernate.dialect.MySQLDialect
20
and the following mapping file:
If execute this, it's working fine:
sessionFactory.getSession().beginTransaction();
sessionFactory.getSession().save(new Table());
sessionFactory.getSession().save(new Table());
sessionFactory.getSession().save(new Table());
sessionFactory.getSession().save(new Table());
sessionFactory.getSession().getTransaction().commit();
However, adding rewriteBatchedStatements=true to hibernate.connection.url:
jdbc:mysql://localhost:3336/db?rewriteBatchedStatements=true
Throws the following exception on commit:
org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 4; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:95)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
Any ideas what's wrong?
解决方案
I also met this issue, and fixed it by updating mysql connector to 5.1.36:
mysql
mysql-connector-java
5.1.36