Hibernate抛出org.hibernate.exception.LockAcquisitionException [英] Hibernate throws org.hibernate.exception.LockAcquisitionException
问题描述
$ pre $ my $ c $ mymethod(long id){
Person p = DAO.findPerson(id );
汽车车=新车();
car.setPerson(p);
p.getCars()。add(car);
DAO.saveOrUpdate(car);
DAO.saveOrUpdate(p);
DAO.delete(p.getCars()。get(0)); //一个人有很多汽车
}
映射:
Person.hbm.xml
<! - one-to-many:[1,1] - > [0,n] - >
< set name =cartable =carslazy =trueinverse =true>
< key column =id_doc/>
<一对多课程=Car/>
< / set>
class =Car
column =officialcar_idlazy =false/>
Cars.hbm.xml
< many-to-one name =personclass =Person
column =id_personnot-null =truelazy =false/>
这个方法适用于单线程,并且在多线程中给我一个错误: p>
02/08/2014 - 5:19:11 pm - [pool-1-thread-35] - WARN - org.hibernate.util.JDBCExceptionReporter - SQL错误:60,SQLState:61000
02/08/2014 - 5:19:11 p.m. - [pool-1-thread-35] - 错误 - org.hibernate.util.JDBCExceptionReporter - ORA-00060:在等待资源时检测到死锁
02/08/2014 - 5:19:晚上11点 - [pool-1-thread-35] - WARN - org.hibernate.util.JDBCExceptionReporter - SQL错误:60,SQLState:61000
02/08/2014 - 5:19:11 p.m. - [pool-1-thread-35] - 错误 - org.hibernate.util.JDBCExceptionReporter - ORA-00060:在等待资源时检测到死锁
02/08/2014 - 5:19:晚上11点 - [pool-1-thread-35] - 错误 - org.hibernate.event.def.AbstractFlushingEventListener - 无法使数据库状态与会话
同步org.hibernate.exception.LockAcquisitionException:无法执行JDBC批量更新
AOP交易:
< tx:advice id =txAdviceNomServicetransaction-manager =txManager>
< tx:attributes>
< tx:method name =*propagation =REQUIREDrollback-for =java.lang.Exception/>
< tx:方法名称=getAll *只读=truepropagation =SUPPORTS/>
< tx:method name =find *只读=truepropagation =SUPPORTS/>
< / tx:属性>
< / tx:advice>
注意:当我在更新后添加Thread.sleep(5000)时,它是可以的。但是这个解决方案并不干净。
我有Cars - >(1 -n)
我在表格的地方有一个外键(id_car)。这个外键没有索引。
当我向这个外键添加索引时,我的问题得到了解决。
I have this method :
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
}
Mapping :
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"/>
This method works well for a single thread, and on multiple threads, gives me an error:
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 Transaction :
<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>
NB : When i add Thread.sleep(5000) after update, it is ok. But this solution is not clean.
I have Cars -> (1 -n) places. And i have a foreign key in the table place (id_car). This foreign key dont have an index. When i add an index to this foreign key, my problem is resolved.
Refer to : Finding cause of deadlock error from oracle trace file
这篇关于Hibernate抛出org.hibernate.exception.LockAcquisitionException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!