a different object with the same identifier value was already associated with the session

This is purely a Hibernate problem. I have one to many relationship between tables. Mapping table c contains the relations between table a and table b. When I try to save a new object in a, which has a set of b objects (All those b objects are already existing), I got an Hibernate exception saying

a different object with the same identifier value was already  associated with the session:
[org.grassfield.common.entity.User#4];  nested exception is org.hibernate.NonUniqueObjectException:
a different  object with the same identifier value was already associated with the  session:
[org.grassfield.common.entity.User#4]

Seems to be quiet common issue for one to many or many to many relationship in hibernate. Need to look at it tomorrow.

Finally I found the table I have created to store the many to many relation is goofy. I removed the id column (autoincrement and PK). It resolved the issue. finally I have only two columns to store the relations.

Done!

—-

Added on 13 Aug 2010

Making cascade=none solved this in another situation.

<many-to-one name=”oldLicense” column=”OLD_LICENSE_ID” cascade=”none” lazy=”false” not-null=”false”/>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s