保存对象时获取 HibernateOptimisticLocking 异常
Getting HibernateOptimisticLocking Exception while saving an object
我有一个模型文件,其代码是:
Signature.java
public class Signature implements Serializable {
private String id;
private int version;
private byte[] signatureImage;
private String signatureImageName;
private String name;
private String title;
// the getters setters methods
}
在此对象中,我使用 MultipartFile
从 jsp 获取 signatureImage
,然后将字节保存到该字段中。我正在从我的控制器中保存这个对象,daohibernate 代码如下:
Session session = getSessionFactory().getCurrentSession();
session.saveOrUpdate(signature);
现在我收到一个错误:
:While Handling request:->HibernateOptimisticLockingFailureException, e:: org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException: Object of class com.model.Signature with identifier []: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [com.model.Signature#]
现在这是对 saveOrUpdate
查询的单次调用,没有线程,然后我也收到此错误。
这里有错误。即将到来的 id 不是 null 它是 "" (empty) 。
所以这就是它试图更新记录而不是保存的原因。
所以通过将 id 的值更改为 null 它保存了记录。
谢谢
我有一个模型文件,其代码是:
Signature.java
public class Signature implements Serializable {
private String id;
private int version;
private byte[] signatureImage;
private String signatureImageName;
private String name;
private String title;
// the getters setters methods
}
在此对象中,我使用 MultipartFile
从 jsp 获取 signatureImage
,然后将字节保存到该字段中。我正在从我的控制器中保存这个对象,daohibernate 代码如下:
Session session = getSessionFactory().getCurrentSession();
session.saveOrUpdate(signature);
现在我收到一个错误:
:While Handling request:->HibernateOptimisticLockingFailureException, e:: org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException: Object of class com.model.Signature with identifier []: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [com.model.Signature#]
现在这是对 saveOrUpdate
查询的单次调用,没有线程,然后我也收到此错误。
这里有错误。即将到来的 id 不是 null 它是 "" (empty) 。
所以这就是它试图更新记录而不是保存的原因。
所以通过将 id 的值更改为 null 它保存了记录。
谢谢