Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Have to add readAllObject before read a single Object?

Thanks, James.
I examined the code carefully, didn't change any objects from the
Session, just read objects.
Because I'm using EclispeLink as toplink persistence provider, the
weird part is, if I change the persistence provider to TopLink, I can
get the right result.
Does EclispeLink and TopLink persistence provider have some differences?

XJ

2010/8/3 James Sutherland <jamesssss@xxxxxxxxx>:
>
> This is very odd.  This should obviously work, it seems you have corrupted
> your cache.
>
> Ensure that you are not changing any objects returned from the Session.
>
> If you set the query to refresh or clear the cache first, it will go to the
> database and indicate that your cache is corrupt.
>
>
>
> Xiangjin Zhou wrote:
>>
>> Hi,
>> I met one problem when I use eclipselink in my project. The following
>> is the problem description.
>>
>> I have two tables in my database schema, one is STUDENT(stu_id, name,
>> age, address, ..., status_id), one is STATUS(status_id, status_name).
>> STUDENT has foreign key status_id, which links to STATUS table. Then I
>> populate 10 records into STUDENT (stu_id, 100~109) and 10 records into
>> STATUS(status_id, 200~209). and the foreign key mapping is
>> stu_id~status_id(100~200, 101~201, ..., 109~209 ). Then I generated
>> two Java POJO corresponding to this two table, Student & Status.
>>
>> The problem happens when I try to load one student's status:
>>
>> UnitOfWork uow = getSessionFactory().acquireUnitOfWork();
>> Student studentCopy = (Student)uow.readObject(Student.class, new
>> ExpressionBuilder().get("stu_id").equal(109));
>> System.out.println(studentCopy.getStatus().getStatusId());
>>
>> The expected result should be 209, but result printed is 200.  If add
>> readAllObjects() inside:
>>
>> UnitOfWork uow = getSessionFactory().acquireUnitOfWork();
>> uow.readAllObjects(Status.class);
>> Student studentCopy = (Student)uow.readObject(Student.class, new
>> ExpressionBuilder().get("stu_id").equal(109));
>> System.out.println(studentCopy.getStatus().getStatusId());
>>
>> The expected result 209 is printed.
>>
>> Do we have add readAllObjects before we try to read a single object
>> and its related Object?
>>
>> Thanks.
>> XJ
>>
>>
>
>
> -----
> http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
> http://www.eclipse.org/eclipselink/
>  EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
> TopLink
> Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink ,
> http://wiki.oracle.com/page/TopLink TopLink
> Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
> http://www.nabble.com/EclipseLink-f26430.html EclipseLink
> Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
> --
> View this message in context: http://old.nabble.com/Have-to-add-readAllObject-before-read-a-single-Object--tp29332795p29336784.html
> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>


Back to the top