File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes NonUniqueObjectException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "NonUniqueObjectException" Watch "NonUniqueObjectException" New topic


Subhash Bhushan C
Ranch Hand

Joined: Jan 27, 2005
Posts: 106

I am trying to use a OneToMany relationship between my MemberDetail Class and its addresses. Here is the code:

The Address class does not have any reference to MemberDetail class.

Creating the Member Detail:

I get the following error upon persisting:
19:37:16,671 ERROR [STDERR] javax.persistence.PersistenceException: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.justbooks.common.entities.Address#0]
19:37:16,687 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(
19:37:16,687 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.persist(
19:37:16,687 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManager.persist(
19:37:16,687 ERROR [STDERR] at

I am using EJB 3.0 persistence with J2EE 1.4/J2SE 5. I assume that Address IDs should be autogenerated. I am using MySQL DB and I have marked the field for autogenerate.

I am sure I am doing something wrong, but not able to pinpoint the problem.

Thanks in advance. Any clues are welcome.

Regards,<br />Subhash Bhushan.
Subhash Bhushan C
Ranch Hand

Joined: Jan 27, 2005
Posts: 106
Figured the problem out.

I was using Hibernate reverse engineering plugin to generate entities from MySQL DB. Some of the entities that have been generated do not have @GeneratedValue annotation. Once I put put it in the entity POJO, things started working fine.
I agree. Here's the link:
subject: NonUniqueObjectException
Similar Threads
ManyToMany relationship with extra field in the joinTable
Persistance issue
Adding data using hibernate for Composite primary keys
jibx binding Error: Nonstatic field name not found in
Create HtmlSelectOneRadio through backing bean