wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes NonUniqueObjectException in Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "NonUniqueObjectException in Hibernate" Watch "NonUniqueObjectException in Hibernate" New topic
Author

NonUniqueObjectException in Hibernate

vamshidhar nimbagiri
Ranch Hand

Joined: Oct 04, 2004
Posts: 61
Hi ,
I am deleting records from a table and 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:

will any body plz help me....

Thanks
vamshidhar


Thanks,
Vamshidhar Nimbagiri
SCJP 5.0
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Can you show us the code you are using?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
vamshidhar nimbagiri
Ranch Hand

Joined: Oct 04, 2004
Posts: 61
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));
}
}
vamshidhar nimbagiri
Ranch Hand

Joined: Oct 04, 2004
Posts: 61
I am getting this exception:


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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NonUniqueObjectException in Hibernate
 
Similar Threads
Adding checkbox in table column
Evaluate data from a ResultSet table and another table where it adds
JPA Lock Table
Displaying the Column Name for JTabel
java.sql.SQLException: "Table 'X' was not locked with LOCK TABLES"