mysql hibernate save,Hibernate + MySQL + rewriteBatchedStatements = true

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值