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)

Shaun,

sorry for late reply, a disease inhibited me.

My comments inlined below:

> 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?

I think the code is not helpful here, it is as simple as I wrote: It
fetches an entity object of type Division which has an @Id field by the
value of this id field. (BTW, does object's identity mean entity
identity?)

For me the relevant log messages are the following:
...
[EPS Finer]: ServerSession(13359904)--client acquired
[EPS Finest]: UnitOfWork(12342678)--Execute query ReadAllQuery(Division)
[EPS Fine]: ServerSession(13359904)--Connection(3807284)--SELECT
DIVISION_ID FROM DIVISIONS WHERE (DIVISION_ID = ?)
	bind => [101]
[EPS Finest]: UnitOfWork(12342678)--Register the existing object
Division@12e7c6a
-> fetchDivision(101) returns: Division@970c0e
...

How I read this messages: In the Unit of Work is an Division object
(Division@12e7c6a) registered. My fetch method returns another Division
object (Division@970c0e). So I have two objects with the same identity,
right? And here I thought pracmatically they have to be the same.

Because this was not the expected result in a second step I implemented
hashCode() and equals() for my Division class to see what's happening
than.

The log shows than:
...
[EPS Finer]: ServerSession(13359904)--client acquired
[EPS Finest]: UnitOfWork(12342678)--Execute query ReadAllQuery(Division)
[EPS Fine]: ServerSession(13359904)--Connection(3807284)--SELECT
DIVISION_ID FROM DIVISIONS WHERE (DIVISION_ID = ?)
	bind => [101]
[EPS Finest]: UnitOfWork(12342678)--Register the existing object
Division@12e7c6a
-> fetchDivision(101) returns: Division@12e7c6a
...

Obviously my method now returns the object which was before registered
by/in the Unit of Work. Strange, or?

If you only use an object's identity, why shows EclipseLink this
behaviour? Or, how I have to read the log in these cases?

Thomas

>
>    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 <http://www.oracle.com>
> Shaun Smith | Principal Product Manager, TopLink | +1.905.502.3094
> Oracle Fusion Middleware
> 110 Matheson Boulevard West, Suite 100
> Mississauga, Ontario, Canada L5R 3P4
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>



Back to the top