Thanks for your reply. Let me explain what I want to do.
I have a table "EMPLOYEE" in the schema and the "EMPLOYEE_ID" is the primary key of this table. There are some rows in this table and one of the row with the "EMPLOYEE_ID" column as "2". Then I want to get this row using the readObject(Object object) method and have the code below:
Employee e = new Employee();
e.setEmployeeId(2);
Employee eCopy = session.readObject(e);
System.out.print(eCopy.getEmployeeId());
In my opinion, the eCopy should be the row what i want to get.
Is this the use case for the readObject method?
regards,
bozhou
Date: Tue, 27 Jul 2010 08:22:23 -0400
From: christopher.delahunt@xxxxxxxxxx
To: eclipselink-users@xxxxxxxxxxx
Subject: Re: Antw.: [eclipselink-users] question about readObject(Object object) method in Session class
Hello Bozhou,
As you are reading from the session, are you making any changes to
objects read directly from the session, or could you be changing the
primary key on the object? EclipseLink uses a cache and when you read
from the session directly you are getting the cached object. Any
changes made to the object are reflected in the cache and may not be
what is in the database. It looks like you might be changing the
objects primary key somewhere as when you insert/persist an object, it
is cached under that key. The only way to cache it under a new key is
to remove/delete it and then insert/persist it under the new key.
Best Regards,
Chris
On 27/07/2010 3:48 AM, bozhou tao wrote:
Hi Jaap,
The primary key for the Employee object is the employeeId and when I
switch the persistence provider to Toplink, I can get the expected
result.
Is there any other configuration I need to do?
thanks,
Bozhou
Date: Mon, 26 Jul 2010 23:36:23 -0700
From:
jaap.spiering@xxxxxxxxxx
To:
eclipselink-users@xxxxxxxxxxx
Subject: Antw.: [eclipselink-users] question about readObject(Object
object) method in Session class
Hi
Bozhou,
what is the primary key of your Employee object?
And do you have the log output for this bit of code? You should
be able to see the SQL that was issued.
regards,
Jaap
----- Oorspronkelijk bericht -----
Van:
bozhou.tao@xxxxxxxxxxx
Aan:
eclipselink-users@xxxxxxxxxxx
Verzonden: Dinsdag 27 juli 2010 04:02:15 GMT +01:00 Amsterdam / Berlijn
/ Bern / Rome / Stockholm / Wenen
Onderwerp: [eclipselink-users] question about readObject(Object object)
method in Session class
Hi,
I'm now using Eclipselink as the persistence provider of Toplink
in my project and for some reason I need to use the readObject(Object
object) method of the Session class.
According to the document:
java.lang.Object readObject(java.lang.Object object)
throws DatabaseException
- PUBLIC: Use the example object to construct a read object query
by the objects primary key. This will read the object from the database
with the same primary key as the object or null if no object is found.
However, when I call this method in my code, the result is not
as I expected. Take the code below for example:
Employee e = new Employee();
e.setEmployeeId(2);
Employee eCopy = session.readObject(e);
System.out.print(eCopy.getEmployeeId());
I think the result should be "2" but the result I get is "1".
Is it design! ed to be that?
Regards,
Bozhou
Hotmail: Trusted email with powerful SPAM protection.
Sign up now.
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
Sign
up now.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users