Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] object/entity identity in EclipseLink (JPA)

Hi there,

I need some help to understand the following two eclipselink log snippets,
which I got with a simple jpa test case - fetching a single object from db
with default configuration settings (cache...). Division is an jpa entity
with an unique identity 101.

In each log snippet the first line is eclipselink output and the second
line shows the hashCode of the returned object.

TC1 Division hasn't implementations for hashCode() and equals() - it
seems, we have two objects with the same entity identity but different
hashCodes.
###
[EPS Finest]: UnitOfWork(23582715)--Register the existing object
Division@12e7c6a
-> fetchDivision(101) returns: Division@49cf9f
###


TC2 Division has implementations for hashCode() and equals() - now we have
one object.
###
[EPS Finest]: UnitOfWork(23582715)--Register the existing object
Division@38766d79
-> fetchDivision(101) returns: Division@38766d79
###

Can somebody explain this effect? Should I always implement hashCode() and
equals() to be sure I have only one object per entity (id)? Or is the fist
case right? Isn't that a problem e.g. for caching?

Thomas




Back to the top