After a call saveOfUpdate(project) sometimes NonUniqueObjectException is thrown. project object have id==0 and is not attached to session.
I've read plenty of topics in the internet, that claims about get()/load() in the incorrect places.
But strangest thing for my problem is that it depends on debugging mode.
When I step into next method and then step over its lines then error does not appear.
Code:
private void addNewProjectToPerson(Person dbPerson) {
project.setPerson(dbPerson);
hibernateSessionFactory.getCurrentSession().saveOrUpdate(project); // here is the place where exception will be thrown
dbPerson.getProjects().add(project);
}
But is I step over this method, then error appears.
I do not understand how debugging mode could be connected with Hibernate exceptions. I believe, that I did not make the same mistake as everybody who usually gets NonUniqueObjectException.
Error scenario is reproducible on the same http calls from browser on the same database data.
Where should I look for the cause of the problem?
Should I try to create something smaller, that shows the same error?
Should I debug Hibernate throws its sources?
Should I try other version of Hibernate?
What else could you suggest me?
I've spend more than two days isolating this error scenario and trying different things to solve it. Looks like I still have this error.
I will be grateful for any help or yours suggestions.
Hibernate version:
3.2.6 + 3.3.1 Hibernate Annotations
Full stack trace of any exception that occurs:
ERROR 22.04.2008 17:13:05,124 [http-8080-Processor23] [[default]] Servlet.service() for servlet default threw exception
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [my.company.entities.Project#26]
at org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:590)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:303)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy20.saveOrUpdate(Unknown Source)
Name and version of the database you are using:
MySQL 5