Sql server Hibernate引发在单个线程中访问的Staleobjectstate异常,该异常由上次修改的时间戳引起
我有一些对象及其hibernate xml遗留系统:Sql server Hibernate引发在单个线程中访问的Staleobjectstate异常,该异常由上次修改的时间戳引起,sql-server,spring,hibernate,exception,last-modified,Sql Server,Spring,Hibernate,Exception,Last Modified,我有一些对象及其hibernate xml遗留系统: <id name="id" type="java.lang.Long"> <column name="id" /> <generator class="increment" /> </id> <timestamp name="lastModifiedOn" column="last_modified_on" /> ... 奇怪的是,更新对象的sql是: up
<id name="id" type="java.lang.Long">
<column name="id" />
<generator class="increment" />
</id>
<timestamp name="lastModifiedOn" column="last_modified_on" />
...
奇怪的是,更新对象的sql是:
update
equipment
set
last_modified_on=?,
created_on=?,
public_id=?,
vendor_id=?,
created_by=?,
last_modified_by=?,
equipment_id=?
where
ID=?
and last_modified_on=?
这是基于ID和上次修改的检查吗?为什么不仅仅是身份证?
数据库中只有ID字段是PK。
只有一个用户正在访问servlet
目前,我已经在整个系统中将上一次修改的时间戳更改为属性,错误消失了。另外,hibernate生成的sql现在只基于ID进行检查
<timestamp name="lastModifiedOn" column="last_modified_on" />
到
但是,现在db datetime中上次修改的字段不会自动更新为最新时间,现在包含null,并且必须以编程方式进行更改,即使使用截取,也很痛苦
有没有什么方法可以让我仍然使用lastModifiedOn作为时间戳,并消除陈旧的对象状态异常 您可以使用版本
在DAO中,您可以在更新之前检查行版本
<version name="rowVersion" column="ROW_VERSION" type="java.lang.Long" />
我不知道你的意思。我应该在所有对象和表中添加另一个列版本以保留版本号,然后更新对象更新的所有位置以添加此检查吗?我在Postgresql上也有类似的问题。数据库中上次修改的时间戳值与Hibernate在更新中使用的java.util.Date lastMondifiedOn值相差几毫秒。
<property type="timestamp" name="lastModifiedOn" column="last_modified_on" />
<version name="rowVersion" column="ROW_VERSION" type="java.lang.Long" />