java - Hibernate StaleDataException while merge -
i have 2 web-service apis. in 1 api, fetch entity , return in sro. api, receive sro, convert entity , use
sessionfactory.getcurrentsession().merge(code);
however, following exception. please me find reason same.
org.springframework.orm.hibernate3.hibernateoptimisticlockingfailureexception: object of class [partnerpromocode] identifier [254874]: optimistic locking failed; nested exception org.hibernate.staleobjectstateexception: row updated or deleted transaction (or unsaved-value mapping incorrect): [partnerpromocode#254874] @ org.springframework.orm.hibernate3.sessionfactoryutils.converthibernateaccessexception(sessionfactoryutils.java:683) @ org.springframework.orm.hibernate3.hibernateexceptiontranslator.converthibernateaccessexception(hibernateexceptiontranslator.java:89) @ org.springframework.orm.hibernate3.hibernateexceptiontranslator.translateexceptionifpossible(hibernateexceptiontranslator.java:68) @ org.springframework.dao.support.chainedpersistenceexceptiontranslator.translateexceptionifpossible(chainedpersistenceexceptiontranslator.java:58) @ org.springframework.dao.support.dataaccessutils.translateifnecessary(dataaccessutils.java:213) @ org.springframework.dao.support.persistenceexceptiontranslationinterceptor.invoke(persistenceexceptiontranslationinterceptor.java:163) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.dao.support.persistenceexceptiontranslationinterceptor.invoke(persistenceexceptiontranslationinterceptor.java:155) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:199) @ sun.proxy.$proxy48.updatepartnerpromocode(unknown source) @ abc.updatepartnerpromocode(abc.java:567) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:616) @ org.springframework.aop.support.aoputils.invokejoinpointusingreflection(aoputils.java:307) @ org.springframework.aop.framework.reflectivemethodinvocation.invokejoinpoint(reflectivemethodinvocation.java:183) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:150) @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:110) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:199) @ sun.proxy.$proxy54.updatepartnerpromocode(unknown source) @ abc.updatepartnerpromocode(servicedealwebservicecontroller.java:272) @ xyz$$fastclassbycglib$$c65431c6.invoke(<generated>) @ net.sf.cglib.proxy.methodproxy.invoke(methodproxy.java:149)
edit
here entity @entity @table(name = "partner_promo_code", catalog = "snapdeal") @namedqueries({ @namedquery(name = querynames.get_unused_partner_promo_code, query = "select p partnerpromocode p p.status=0 , p.partnercode = :partnercode , p.catalogid = :catalogid order p.id"), @namedquery(name = querynames.get_partner_promo_code_by_promo, query = "from partnerpromocode partnercode = :partnercode , promocode = :promocode") }) public class partnerpromocode implements java.io.serializable {
public static final boolean status_used = true; public static final boolean status_not_used = false; /** * */ private static final long serialversionuid = 7786688992136091701l; private integer id; private string partnercode; private string promocode; private boolean status; private date expiry; private date created; private date updated; public partnerpromocode() { } public partnerpromocode(string partnercode, string promocode) { this.partnercode = partnercode; this.promocode = promocode; this.status = status_not_used; } @id @generatedvalue(strategy = identity) @column(name = "id", unique = true, nullable = false) public integer getid() { return this.id; } public void setid(integer id) { this.id = id; } @column(name = "partner_code") public string getpartnercode() { return partnercode; } public void setpartnercode(string partnercode) { this.partnercode = partnercode; } @column(name = "promo_code") public string getpromocode() { return promocode; } public void setpromocode(string promocode) { this.promocode = promocode; } @column(name = "status") public boolean getstatus() { return status; } public void setstatus(boolean status) { this.status = status; } @temporal(temporaltype.timestamp) @column(name = "expiry", nullable = false, length = 19) public date getexpiry() { return expiry; } public void setexpiry(date expiry) { this.expiry = expiry; } @temporal(temporaltype.timestamp) @column(name = "created", nullable = false, length = 19) public date getcreated() { return created; } public void setcreated(date created) { this.created = created; } @version @column(name = "updated", nullable = false, length = 19) public date getupdated() { return updated; } public void setupdated(date updated) { this.updated = updated; }
}
i fetching entity id , converting sro,,,passing on wire...then later on receive sro, create new entity object , set id , every other fields, set updated field current time , try merge entity through sessionfactory.getsession().merge(obj)
because value of field annotated @version
doesn't match value stored in database (or because row in database doesn't exist anymore).
Comments
Post a Comment