TopLink Wiki
Main
RecentChanges
Set your name in
UserPreferences
Referenced by
JSPWiki v2.0.52
|
A common TopLink problem is creating a new object through the UOW, and wanting to access it later (before commit). Because the object is new, it doesn't have a primary key yet, and one is therefore unable to look it up.
Person personClone = (Person) uow.newInstance(Person.class);
personClone.setId(1);
personClone.setName("me");
// uow.commit(); --- not committed
ExpressionBuilder builder = new ExpressionBuilder();
Expression expr = builder.get("name").equal("me");
Person personFound = (Person) session.readObject(Person.class, expr);
// personFound is null
Possible solutions:
session.setProperty("NEW PERSON", personClone);
// later
Person newPerson = (Person) session.getProperty("NEW PERSON");
See Also
The UnitOfWorkPrimer discusses this trick also.
|
||||||