为什么Hibernate抛出org.hibernate.exception.LockAcquisitionException?
发布于 2021-02-01 12:40:07
我有这种方法:
mymethod(long id){
Person p = DAO.findPerson(id);
Car car = new Car();
car.setPerson(p);
p.getCars().add(car);
DAO.saveOrUpdate(car);
DAO.saveOrUpdate(p);
DAO.delete(p.getCars().get(0));//A person have many cars
}
映射:
Person.hbm.xml
<!-- one-to-many : [1,1]-> [0,n] -->
<set name="car" table="cars" lazy="true" inverse="true">
<key column="id_doc" />
<one-to-many class="Car" />
</set>
<many-to-one name="officialCar"
class="Car"
column="officialcar_id" lazy="false"/>
Cars.hbm.xml
<many-to-one name="person" class="Person"
column="id_person" not-null="true" lazy="false"/>
此方法适用于单个线程,并且在多个线程上,给我一个错误:
02/08/2014 - 5:19:11 p.m. - [pool-1-thread-35] - WARN - org.hibernate.util.JDBCExceptionReporter - SQL Error: 60, SQLState: 61000
02/08/2014 - 5:19:11 p.m. - [pool-1-thread-35] - ERROR - org.hibernate.util.JDBCExceptionReporter - ORA-00060: deadlock detection while waiting for a resource
02/08/2014 - 5:19:11 p.m. - [pool-1-thread-35] - WARN - org.hibernate.util.JDBCExceptionReporter - SQL Error: 60, SQLState: 61000
02/08/2014 - 5:19:11 p.m. - [pool-1-thread-35] - ERROR - org.hibernate.util.JDBCExceptionReporter - ORA-00060: deadlock detection while waiting for a resource
02/08/2014 - 5:19:11 p.m. - [pool-1-thread-35] - ERROR - org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.LockAcquisitionException: Could not execute JDBC batch update
AOP交易:
<tx:advice id="txAdviceNomService" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
<tx:method name="getAll*" read-only="true" propagation="SUPPORTS" />
<tx:method name="find*" read-only="true" propagation="SUPPORTS" />
</tx:attributes>
</tx:advice>
注意:当我在更新后添加Thread.sleep(5000)时,就可以了。 但是这种解决方案并不干净。
关注者
0
被浏览
108
1 个回答
推荐阅读
-
Hibernate抛出java.lang.NoClassDefFoundError:org / hibernate / internal / CoreMessageLogger
2021-02-01 关注 0 浏览101 1答案
-
org.hibernate.exception.SQLGrammarException:无法执行语句
2021-02-01 关注 0 浏览96 1答案
-
org.hibernate.exception.GenericJDBCException:无法执行查询
2021-02-01 关注 0 浏览107 1答案
-
NamedEntityGraph-JPA /Hibernate抛出org.hibernate.loader.MultipleBagFetchException:无法同时获取多个包
2021-02-01 关注 0 浏览99 1答案
-
org.hibernate.exception.SQLGrammarException:无法插入[com.sample.Person]
2021-02-01 关注 0 浏览81 1答案
-
为什么我得到org.hibernate.HibernateException:没有配置CurrentSessionContext
2021-02-01 关注 0 浏览124 1答案
-
Hibernate 抛出 org.hibernate.AnnotationException:没有为实体指定标识符:com..domain.idea.MAE_MFEView
2022-05-26 关注 0 浏览12 1答案
-
Hibernate抛出org.hibernate.AnnotationException:未为实体指定标识符:com..domain.idea.MAE_MFEView
2021-02-01 关注 0 浏览68 1答案
-
获取org.hibernate.exception.JDBCConnectionException:即使通过JNDI也无法执行查询
2021-02-01 关注 0 浏览86 1答案
-
Hibernate和@JoinFormula:org.hibernate.mapping.Formula无法转换为org.hibernate.mapping.Column
2021-02-01 关注 0 浏览101 1答案