Skip to main content

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

Hi Thomas,

   EclipseLink does not make use of hashCode() and equals() in it's cache management.  We use an object's identity.  It's not clear from the log what your code is doing.  Can you show your code and the log messages inlined?

   Repeated queries for the same object on the same EntityManager will give you back the exact same instance.  Each will be == the other.  If you query against different EntityManagers you will get different instances that are not from the same persistence context and are not ==.

    Shaun

Thomas Paradies wrote:
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


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
  

--


Oracle
Shaun Smith | Principal Product Manager, TopLink | +1.905.502.3094
Oracle Fusion Middleware
110 Matheson Boulevard West, Suite 100
Mississauga, Ontario, Canada L5R 3P4

Back to the top