Using JPA, I stumbled upon the problem with equals()
and hashcode()
, especially for newly created entities which have not yet been persisted.
I found the following answer in stackoverflow:
Should I write equals() methods in JPA entities?
This answer talks about Hibernate sessions. I do not use Hibernate (but EclipseLink), and I don't know about implementation specifics of JPA providers, such as these "sessions".
My question is, what is a Hibernate session in terms of JPA? Or, more specific: If I don't override equals()
and hashcode()
, in which cases would I run into the problem where two objects representing the same entity (same business key, if one exists) are not "equal" (this means equals()
returns false)?
Will using the same EntityManager instance be sufficient to not getting these problems (this means, can "session" and "EntityManager" be used equivalent in this context?)
Note: I don't have a usable business key for all tables, so the solution to use business key attributes in equals()
and hashcode()
cannot be applied.