How do these Hibernate objects differ? [duplicate]
-
07-09-2020 - |
Question
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().
OTHER TIPS
db.item.model.Inventory@21d321bb refers to a memory address.
db.item.model.Inventory#9369629 refers to an entity with ID 9369629.
db.item.model.Inventory@21d321bb is a certain instance. [db.item.model.Inventory#9369629] are two or more instances with @Id 9369629.