1

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?

Community
  • 1
  • 1
Rihards
  • 10,241
  • 14
  • 58
  • 78

3 Answers3

4

db.item.model.Inventory@21d321bb refers to a memory address.

db.item.model.Inventory#9369629 refers to an entity with ID 9369629.

Marcelo
  • 11,218
  • 1
  • 37
  • 51
  • But they can be the same objects, can't they? – Rihards May 20 '11 at 14:32
  • They sure can, there is just an inconsistency with the Exception Message Text. Best way to figure if they refer to the same ID is using your debugger or writing out the id property to the console. – Marcelo May 20 '11 at 14:34
2

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().

Aravindan R
  • 3,084
  • 1
  • 28
  • 44
0

db.item.model.Inventory@21d321bb is a certain instance. [db.item.model.Inventory#9369629] are two or more instances with @Id 9369629.