Skip to main content

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

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


Back to the top