Hibernate + MySQL + rewriteBatchedStatements = true [英] Hibernate + MySQL + rewriteBatchedStatements=true
本文介绍了Hibernate + MySQL + rewriteBatchedStatements = true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的Hibernate配置:
I'm having the following Hibernate configuration:
<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>
和以下映射文件:
and the following mapping file:
<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>
如果执行此操作,它工作正常:
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();
但是,将 rewriteBatchedStatements = true
添加到 hibernate.connection.url
:
<prop key="hibernate.connection.url">jdbc:mysql://localhost:3336/db?rewriteBatchedStatements=true</prop>
抛出以下异常:
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)
任何想法有什么不对?
推荐答案
我也遇到了这个问题,并通过将mysql连接器更新为5.1来修复它。 36:
I also met this issue, and fixed it by updating mysql connector to 5.1.36:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
这篇关于Hibernate + MySQL + rewriteBatchedStatements = true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文