Search code examples
javahibernatehibernateexception

How do these Hibernate objects differ?


Possible Duplicate:
Hibernate: different object with the same identifier value was already associated with the session

Why does some objects I get in Hibernate exceptions appear like this when they are printed out with the @ symbol:

Cannot remove object

db.item.model.Inventory@21d321bb

But some appear like this:

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [db.item.model.Inventory#9369629]

With the identifier after # symbol?


Solution

  • The identifier after the # is the primary key of the object in the table.

    A NonUniqueObjectException occurs when two objects with the same identifier (primary key) are added to the session.

    db.item.model.Inventory@21d321bb is output by the default equals method i.e. Object.equals().