2013-03-14 92 views
0

我已经继承了一个应用程序,它执行一些基于触发器的插入和更新,偶尔会抛出StaleObjectException。我试图添加很多调试(tx,hibernate,type等),这让我更加困惑。StaleObjectException,但真的很奇怪

15:21:00 Calling dao.insert 
15:21:00 starting Trancation T1 
15:21:01 insert records including object #290595 
15:21:01 Transaction T1 commits 

我看到日志中的tx提交,hibernate插入和数据,实际上id为#290595的对象被绑定为值。在15:24:00有一个类似的插入,但直到15:25:00该应用程序完全沉默(没有用户,没有其他活动)。

15:25:00 Start a Required_new transaction T2 
15:25:00 Calling dao.finder 
15:25:01 dao transaction uses propagated T2 
15:25:01 Select returns object with id #290595 
15:25:01 ends propagated transacted finder 
15:25:02 calling dao.update 
15:25:02 dao transaction uses propagated T2 
15:25:02 binds object with id #290595 
15:25:02 Could Not Synchronize Database State With Session (StaleObjectStateException) 

数据库中的sql查询显示记录#290595确实不存在。插入和失败之间有4分钟。不用说,这通常是一天中大部分时间工作,但突然......

不会自动刷新和提交事务提交?

我假设插入已将数据移到缓存但不是数据库,在缓存中再次找到,但拒绝更新,因为它们不在数据库中。所以问题是,如果任何人有任何伟大的想法?

它是一个oracle数据库,我试图确保T2具有Required_new事务,并与isolation_level序列化,但效果不大。我开始认为插入是不知不觉中,?!

任何建议welcom

回答

0

嗯,我自己找到了答案。

我偶然发现的Javadoc StaleObjectStateException in Hibernate ver 2

Thrown when a version number or timestamp check failed, indicating that the Session 
contained stale data (when using long transactions with versioning). Also occurs 
if we try delete or update a row that does not exist. 

我一直以为第二,从来不看first..Version确实时间戳和阅读this article以及之后我修改的版本属性到很久以后,所有的错误都消失了。不确定差异,但它对应用程序逻辑没有影响,所以..?

为什么有人想使用时间戳进行版本控制呢?