我有以下 Hibernate 配置:
<prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
<prop key="hibernate.connection.url">jdbc:mysql://localhost:3336/db</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
以及以下映射文件:
<hibernate-mapping default-lazy="false">
<class name="Table" table="TABLE" batch-size="10" dynamic-update="true">
<id name="id" column="ID">
<generator class="uuid"/>
</id>
<property name="name" column="NAME" not-null="true"/>
</class>
</hibernate-mapping>
如果执行这个,它工作正常:
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();
然而,添加rewriteBatchedStatements=true
to hibernate.connection.url
:
<prop key="hibernate.connection.url">jdbc:mysql://localhost:3336/db?rewriteBatchedStatements=true</prop>
提交时抛出以下异常:
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)
任何想法有什么问题吗?
我使用的是 MySQL Connector/J 5.1.28,它有这个错误:http://bugs.mysql.com/bug.php?id=68562 http://bugs.mysql.com/bug.php?id=68562。降级到 5.1.24 解决了该问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)