我将Hibernate与wildfly 10.0.1一起使用。我的交易是Container managed Transaction。
更新条目时,我经常会[1] OptimisticLockException
。
如何在CMT中处理此异常?
为什么我的野蝇管理得不好?
我是否需要添加任何应用程序级逻辑?
[1]
javax.persistence.OptimisticLockException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
的persistence.xml
<persistence-unit name="apidb-persistence-unit"
transaction-type="JTA">
<description>Forge Persistence Unit</description>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/lobDS</jta-data-source>
<class>xx.core.model.base.CRMEntity</class>
<class>xx.model.base.Company</class>
..
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="admin" />
<property name="javax.persistence.jdbc.password" value="ss_password" />
<!-- Scan for annotated classes and Hibernate mapping XML files -->
<property name="hibernate.archive.autodetection" value="class, hbm" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.hbm2ddl.auto" value="" />
<property name="hibernate.enable_lazy_load_no_trans" value="true" />
<property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2" />
<property name="hibernate.connection.provider_class" value="com.zaxxer.hikari.hibernate.HikariConnectionProvider" />
<property name="hibernate.hikari.minimumIdle" value="5" />
<property name="hibernate.hikari.maximumPoolSize" value="500" />
<property name="hibernate.hikari.idleTimeout" value="30000" />
<property name="hibernate.hikari.dataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" />
<property name="hibernate.hikari.dataSource.url" value="jdbc:mysql://localhost:3306/rathadb" />
<property name="hibernate.hikari.dataSource.user" value="XX" />
<property name="hibernate.hikari.dataSource.password" value="XX" />
<property name="hibernate.hikari.dataSource.cachePrepStmts" value="true" />
<property name="hibernate.hikari.dataSource.prepStmtCacheSize" value="1000" />
<property name="hibernate.hikari.dataSource.prepStmtCacheSqlLimit" value="2048" />
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.discriminator.ignore_explicit_for_joined" value="true" />