Using JPA, I came across a problem with equals() and hashcode() , especially for newly created objects that have not yet been saved.
I found the following answer on stackoverflow:
Should I write equals () methods in JPA objects?
This answer talks about Hibernate sessions. I do not use Hibernate (but EclipseLink), and I do not know about the specifics of the implementation of JPA providers, such as these "sessions".
My question is: what is a Hibernate session from a JPA perspective? Or more specifically: if I do not redefine equals() and hashcode() , in which cases I would run into a problem when two objects representing the same object (the same business key, if one exists) are not " equal to "(does this mean that equals() returns false)?
Will the same EntityManager instance be used to not get these problems (does this mean that in this context you can use the equivalent in "session" and "EntityManager"?)
Note. I do not have a useful business key for all tables, so the decision to use the business key attributes in equals() and hashcode() cannot be applied.
source share