You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Juergen Ebert <ju...@web.de> on 2003/09/07 13:46:39 UTC
Question on QueryByIdenty
I've written a test case that queries for an object with a
QueryByIdentity after it has been deleted from the database. Contrary to
my expectations, broker.getObjectByQuery() still returns an object
instead of null!
Null is only returned if I either use QueryByCriteria instead of
QueryByIdentity or if I remove a previous lookup operation (please see
below).
Could someone please tell me what is going on here? I'm using OJB 1.0
RC4. Here is the code:
PersistenceBroker broker =
PersistenceBrokerFactory.defaultPersistenceBroker();
Lv lv = new Lv("Test");
broker.beginTransaction();
broker.store(lv);
broker.commitTransaction();
int oid = lv.getObjectId();
Identity id = new Identity(Lv.class, LvObject.class, new Object[] {
new Integer(oid) });
Query query = QueryFactory.newQuery(id);
/* This works!
Criteria crit = new Criteria();
crit.addEqualTo("objectId", new Integer(oid));
Query query = QueryFactory.newQuery(Lv.class, crit);
*/
// retrieve again (It works if this step is removed!)
lv = (Lv)broker.getObjectByQuery(query);
assertNotNull(lv);
// delete
broker.beginTransaction();
broker.delete(lv); // rows are successfully deleted from database!
broker.commitTransaction();
// retrieve again
lv = (Lv)broker.getObjectByQuery(query);
assertNull("Lv should be null after delete", lv);
broker.close();
Thanks,
Jürgen
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org