我正在使用带有hibernate的spring orm。我有一个方法如下
对象有版本列。@ Version。
void processObject(){
Object obj = getObjectFromDB(int id);
//do lot of processing. Takes 15 min
//version number is not changed
//if some other object updates the same object , which
//exception is thrown when folloing code runs
updateObject(obj) ;
//
}
@Transactional
updateObject(Object object){
session.save(object)
}
@Transcational
Object getObjectFromDB(int id){
}
现在,如果某个其他线程在处理并保存对象时更新了对象,那么将抛出哪个异常?
1)StaleStateException (hibernate)
2)StaleObjectstateException (hibernate)
3)ConcurrentFailureException (spring)
4)Any other?
答案 0 :(得分:0)
底层的orm(休眠),将抛出
org.hibernate.StaleObjectStateException
然后Spring数据访问层将捕获它,并将其包装在
中org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException
因此,您将获得的堆栈跟踪将是:
org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException:
Caused by: org.hibernate.StaleObjectStateException:
您可以阅读hibernate optimistic locking和spring exception translation