java - a different object with the same identifier value was already associated with the session in case of saveOrUpdateAll in Hibernate3 -


in case of modify it's giving org.hibernate.nonuniqueobjectexception. in bidderbo class

@override @transactional(propagation=propagation.required, rollbackfor=exception.class) public boolean updatebidder(biddersdetailform bidderdetailform, missessionbean missessionbean) throws misexception {     boolean status = false;     boolean childstatus =false;     try {         bidderheaderbean bidderheaderbean = populabidderheaderbean(bidderdetailform);          misauditbean misauditbean = new misauditbean();         misauditbean.setstatus(misconstants.master_status_verified);         misauditbean.setentby(missessionbean.getenteredby());         misauditbean.setentdate(missessionbean.getentereddate());         bidderheaderbean.setmisauditbean(misauditbean);          status = bidderheaderdao.updatebidderheader(bidderheaderbean);          if(status){             long bidderinfoid = bidderdetailform.getbidinfoid();             list<bidderdetailbean> bidderdetailbeans = populatebidderdetailbeans(bidderdetailform, bidderinfoid,  missessionbean, misconstants.master_status_verified);             log.debug("\nbidder detailbeans\t"+bidderdetailbeans);             for(bidderdetailbean bidderdetailbean:bidderdetailbeans ){                 log.debug("bank name  ==========="+bidderdetailbean.getbankname());                 log.debug("bid amount ==========="+bidderdetailbean.getbidamount());                 log.debug("getbiddername ==========="+bidderdetailbean.getbiddername());                 log.debug("getbidinfoid ==========="+bidderdetailbean.getbidinfoid());                 log.debug("getseqbidid ==========="+bidderdetailbean.getseqbidid());                 log.debug("status ==========="+bidderdetailbean.getmisauditbean().getstatus());                 log.debug("bid sale date ==========="+bidderdetailbean.getmisauditbean().getentdate());                  }             childstatus = bidderdetaildao.updatebidderdetailbeans(bidderdetailbeans);             if(!childstatus){                 throw new misexception(misexceptioncodes.mis003, "bidder details not updated "+bidderdetailform.gettenderid());             }          }     } catch (dataaccessexception e) {         log.error(e.getlocalizedmessage(),e);         throw new misexception(e.getmostspecificcause());     } catch (misexception e) {         log.error(e.getlocalizedmessage(),e);         throw e;     }     return status && childstatus; } 

and bean (bidderdetailbean)

public class bidderdetailbean implements serializable {   /**  * initial version  */ private static final long serialversionuid = -2234569083113434751l;   @id @generatedvalue(generator = "seq_bid_id", strategy = generationtype.auto) @sequencegenerator(name = "seq_bid_id", sequencename = "prwss_main.seq_bid_id") @column(name = "seq_bid_id", nullable = false) private long seqbidid;   @column(name="bid_info_id", nullable=false) private long bidinfoid;   @column(name="bidder_name", nullable=false) private string biddername;  @column(name="bid_sale_date") private date bidsaledate;  @column(name="bid_submitted") private string bidsubmitted;  @column(name="emd_amount") private double emdamount;  @column(name="emd_valid_upto") private date emdvalidupto;  @column(name="emd_instrument_type") private string emdinstrumenttype;  @column(name="bank_name") private string bankname;  @column(name="not_responsive") private string notresponsive;  @column(name="bidder_contact_number") private string contactnumber;  @column(name="remarks") private string remarks;  @column(name="bid_amount") private double bidamount;  @embedded private misauditbean misauditbean;  public long getbidinfoid() {     return bidinfoid; }  public void setbidinfoid(long bidinfoid) {     this.bidinfoid = bidinfoid; }  public string getbiddername() {     return biddername; }  public void setbiddername(string biddername) {     this.biddername = biddername; }  public date getbidsaledate() {     return bidsaledate; }  public void setbidsaledate(date bidsaledate) {     this.bidsaledate = bidsaledate; } 

.................................

and bidderheaderbean .....

public class bidderheaderbean implements serializable {  /**  * initial version  */ private static final long serialversionuid = 6163541390640145180l;  @id @sequencegenerator(name="seq_bid_info_id",      sequencename="prwss_main.seq_bid_info_id") @generatedvalue(generator="seq_bid_info_id", strategy=generationtype.auto) @column(name="bid_info_id", nullable=false) private long bidinfoid;  @column(name="location_id") private string locationid;  @column(name="tender_id") private string tenderid;  @column(name="bidding_phase") private int biddingphase;  @column(name="bid_opening_date") private date bidopeningdate;  @column(name="reference_tender_id") private string referencetenderid;  @embedded private misauditbean misauditbean;  @onetomany(targetentity=bidderdetailbean.class, fetch=fetchtype.eager) @joincolumn(name="bid_info_id", insertable=false, updatable=false) private set<bidderdetailbean> bidderdetailbeans;  public long getbidinfoid() {     return bidinfoid; }  public void setbidinfoid(long bidinfoid) {     this.bidinfoid = bidinfoid; }  

and daoimpl class using function........

@override public boolean saveorupdatebidderdetailbeans(collection<bidderdetailbean> bidderdetailbeans) throws dataaccessexception {      try {         system.out.println("bidderdetailbeans----in dao===="+bidderdetailbeans.tostring());         gethibernatetemplate().flush();         gethibernatetemplate().saveorupdateall(bidderdetailbeans);         gethibernatetemplate().flush();         gethibernatetemplate().clear();     } catch (dataaccessexception e) {         throw e;     }      return true; } 

please give guide have tried clear function , merge , saveorupdate it's not working . it's giving error ............

2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] bank name  ===========state bank of patiala 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] bid amount ===========1452250.0 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] getbiddername ===========7575 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] getbidinfoid ===========3517 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] getseqbidid ===========5268 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] status ===========u 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] bid sale date ===========2014-06-27 10:04:46.857 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] bank name  ===========state bank of patiala 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] bid amount ===========992620.0 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] getbiddername ===========ven00002 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] getbidinfoid ===========3517 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] getseqbidid ===========5267 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] status ===========d 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] bid sale date ===========2014-06-27 10:04:46.857 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] bank name  ===========state bank of patiala 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] bid amount ===========1452250.0 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] getbiddername ===========7575 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] getbidinfoid ===========3517 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] getseqbidid ===========5268 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] status ===========d 2014-06-27 10:10:08,659 debug [com.prwss.mis.tender.bidderboimpl] bid sale date ===========2014-06-27 10:04:46.857 2014-06-27 10:10:08,667 error [com.prwss.mis.tender.bidderboimpl] different object same identifier value associated session: [com.prwss.mis.tender.biddersdetail.dao.bidderdetailbean#5268]; nested exception org.hibernate.nonuniqueobjectexception: different object same identifier value associated session: [com.prwss.mis.tender.biddersdetail.dao.bidderdetailbean#5268] org.springframework.orm.hibernate3.hibernatesystemexception: different object same identifier value associated session: [com.prwss.mis.tender.biddersdetail.dao.bidderdetailbean#5268]; nested exception org.hibernate.nonuniqueobjectexception: different object same identifier value associated session: [com.prwss.mis.tender.biddersdetail.dao.bidderdetailbean#5268]     @ org.springframework.orm.hibernate3.sessionfactoryutils.converthibernateaccessexception(sessionfactoryutils.java:679)     @ org.springframework.orm.hibernate3.hibernateaccessor.converthibernateaccessexception(hibernateaccessor.java:412)     @ org.springframework.orm.hibernate3.hibernatetemplate.doexecute(hibernatetemplate.java:411)     @ org.springframework.orm.hibernate3.hibernatetemplate.executewithnativesession(hibernatetemplate.java:374)     @ org.springframework.orm.hibernate3.hibernatetemplate.saveorupdateall(hibernatetemplate.java:757)     @ com.prwss.mis.tender.biddersdetail.dao.bidderdetaildaoimpl.saveorupdatebidderdetailbeans(bidderdetaildaoimpl.java:53)     @ com.prwss.mis.tender.bidderboimpl.updatebidder(bidderboimpl.java:131)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)     @ java.lang.reflect.method.invoke(method.java:597)     @ org.springframework.aop.support.aoputils.invokejoinpointusingreflection(aoputils.java:309)     @ 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:202)     @ $proxy34.updatebidder(unknown source)     @ com.prwss.mis.tender.struts.biddersdetailaction.update(biddersdetailaction.java:318)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)     @ java.lang.reflect.method.invoke(method.java:597)     @ org.apache.struts.actions.dispatchaction.dispatchmethod(dispatchaction.java:269)     @ org.apache.struts.actions.dispatchaction.execute(dispatchaction.java:170)     @ org.springframework.web.struts.delegatingactionproxy.execute(delegatingactionproxy.java:113)     @ org.apache.struts.chain.commands.servlet.executeaction.execute(executeaction.java:58)     @ org.apache.struts.chain.commands.abstractexecuteaction.execute(abstractexecuteaction.java:67)     @ org.apache.struts.chain.commands.actioncommandbase.execute(actioncommandbase.java:51)     @ org.apache.commons.chain.impl.chainbase.execute(chainbase.java:191)     @ org.apache.commons.chain.generic.lookupcommand.execute(lookupcommand.java:305)     @ org.apache.commons.chain.impl.chainbase.execute(chainbase.java:191)     @ org.apache.struts.chain.composablerequestprocessor.process(composablerequestprocessor.java:283)     @ org.apache.struts.action.actionservlet.process(actionservlet.java:1913)     @ org.apache.struts.action.actionservlet.dopost(actionservlet.java:462)     @ javax.servlet.http.httpservlet.service(httpservlet.java:637)     @ javax.servlet.http.httpservlet.service(httpservlet.java:717)     @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:290)     @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206)     @ org.displaytag.filter.responseoverridefilter.dofilter(responseoverridefilter.java:125)     @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:235)     @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206)     @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:233)     @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:191)     @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:127)     @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:102)     @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:109)     @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:298)     @ org.apache.coyote.http11.http11aprprocessor.process(http11aprprocessor.java:861)     @ org.apache.coyote.http11.http11aprprotocol$http11connectionhandler.process(http11aprprotocol.java:579)     @ org.apache.tomcat.util.net.aprendpoint$worker.run(aprendpoint.java:1584)     @ java.lang.thread.run(thread.java:662) caused by: org.hibernate.nonuniqueobjectexception: different object same identifier value associated session: [com.prwss.mis.tender.biddersdetail.dao.bidderdetailbean#5268]     @ org.hibernate.engine.statefulpersistencecontext.checkuniqueness(statefulpersistencecontext.java:638)     @ org.hibernate.event.def.defaultsaveorupdateeventlistener.performupdate(defaultsaveorupdateeventlistener.java:305)     @ org.hibernate.event.def.defaultsaveorupdateeventlistener.entityisdetached(defaultsaveorupdateeventlistener.java:246)     @ org.hibernate.event.def.defaultsaveorupdateeventlistener.performsaveorupdate(defaultsaveorupdateeventlistener.java:112)     @ org.hibernate.event.def.defaultsaveorupdateeventlistener.onsaveorupdate(defaultsaveorupdateeventlistener.java:93)     @ org.hibernate.impl.sessionimpl.firesaveorupdate(sessionimpl.java:685)     @ org.hibernate.impl.sessionimpl.saveorupdate(sessionimpl.java:677)     @ org.hibernate.impl.sessionimpl.saveorupdate(sessionimpl.java:673)     @ org.springframework.orm.hibernate3.hibernatetemplate$18.doinhibernate(hibernatetemplate.java:761)     @ org.springframework.orm.hibernate3.hibernatetemplate.doexecute(hibernatetemplate.java:406)     ... 49 more   

this exception thrown whenever call saveorupdate (which means session entity attachment) entity has been attached current session.

a workaround use merge attached entity if there none attached, in case merges attached 1 current entity given parameter.

bidderheaderbean has non insertable/updatable children association:

@onetomany(targetentity=bidderdetailbean.class, fetch=fetchtype.eager) @joincolumn(name="bid_info_id", insertable=false, updatable=false) private set<bidderdetailbean> bidderdetailbeans; 

which not mappedby or inverse one. bidderdetailbean doesn't have association bidderheaderbean either, association never work, since foreign key never inserted/updated.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -