Tin*_*iny 3 hibernate jpa spring-mvc java-ee
我在WebApp中收到以下错误:
Handling an unexpected exception in webApp:
- javax.servlet.error.status_code = 500
- javax.servlet.error.exception_type = class org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException
- javax.servlet.error.message = Object of class [domain.entity.common.dataEntity] with identifier [110837262]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [domain.entity.common.dataEntity
我不确定为什么会发生此错误,它发生在下面的行中.
SpecEntity specTemp = this.persistService.merge(specTemp);
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
在这种情况下,HibernateOptimisticLockingFailureException当您尝试调用另一个事务已经同时更新merge的entity(specTaskTemp)时,就会发生异常.
如果查看SpecEntity类,则必须定义@Version列.hibernate将使用它来检查您合并的实体是否早于数据库中的实体.
样品流程:
SpecEntity版本列值为的实体SpecEntity与版本值1 相同的内容.HibernateOptimisticLockingFailureException.根据您的使用情况,您可以entity从数据库重新加载更新updated data并向用户显示,以便用户可以决定下一步该做什么.
或者,如果要继续使用specTaskTemp实体中的数据覆盖数据库中的数据,可以从数据库中获取此实体的最新版本,将其版本值复制到specTaskTemp实体,然后调用该merge调用.
| 归档时间: |
|
| 查看次数: |
4407 次 |
| 最近记录: |