-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: org.hibernate.NonUniqueObjectException:
PostPosted: Fri Jan 13, 2006 4:41 pm 
Newbie

Joined: Fri Jan 13, 2006 4:36 pm
Posts: 2
Hi
i am insering into table using save() method.
but i am getting this exception.

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:

My code:
public void insert(String filePath, String state) throws IOException
{
List stateInfo = parseFile(filePath);

deleteRecords(state);

insertRecords(stateInfo);
}

public void deleteRecords(String state)
{
Session hs = getCurrentSQLServer2000Session();
int noOfRowsDeleted = hs.createQuery(DELETE_RECORDS_BY_STATE_HQL).setString(0,state).executeUpdate();
}


public void insertRecords(List recordsToInsert)
{
Session hs = getCurrentSQLServer2000Session();

for(int i=0;i<recordsToInsert.size();i++)
{
hs.save(recordsToInsert.get(i));
}
}

Stact Trace:

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.wpsmedicare.corporate.entity.medicare.MedicareProvider# ]
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java:73)
at org.hibernate.exception.NestableRuntimeException.<init>(NestableRuntimeException.java:100)
at org.hibernate.NonUniqueObjectException.<init>(NonUniqueObjectException.java:22)
at org.hibernate.NonUniqueObjectException.<init>(NonUniqueObjectException.java:28)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
at java.lang.reflect.Method.invoke(Method.java)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:555)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:114)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)
Committing database transaction of this thread.


Please help me how to resolve this

Thanks,
vamshi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 7:12 pm 
Newbie

Joined: Mon Nov 28, 2005 11:01 am
Posts: 11
It doesn't look like you are using servlet filters and Open Session in View pattern (http://www.hibernate.org/43.html). How do you manage your session?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 14, 2006 3:38 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Do you have any objects that you are deleting also in the list for Insertions?
If you have already have a object persisted(and also unsaved objects), you should use saveOrUpdate instead of save just to avoid this kind of errors.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.