I have code like this (don't mind copy paste and other possible snip snap compile errors) :
PersistenceManager manager = null;
Transaction tx = null;
Object dbObject = null;
User user = new User("nosuchuser");try {
manager = factory.getPersistenceManager();Identity oid = new Identity(user,PersistenceBrokerFactory.defaultPersistenceBroker()); tx = manager.currentTransaction(); tx.begin();
dbObject = manager.getObjectById(oid, false);
if (dbObject == null) {
throw new ObjectNotFoundException("User was not found in database");
}
// fetch all fields
manager.retrieve(dbObject);
manager.makeTransient(dbObject);
logger.debug("Got object from database: " + dbObject);tx.commit();
} catch (ObjectNotFoundException unfe) {
// expected exception, let it pass
throw unfe;
} catch (Exception e) {
logger.error("Exception caught:", e);
if ((tx != null) && tx.isActive()) {
tx.rollback();
} logger.error("Error fetching object from datastore " + dbObject, e);
} finally {
logger.debug("finally{} closing the manager.");
manager.close();
}The problem is that there is no user with primary key "nosuchuser" but getObjectById returns some kind of user object instead of null. This object is in a really inconsistent state. The code will crash into OJB's NPE when the manager.retrieve is called. Does anyone else have this kind of problem, the examples for JDO API usage state that null is returned if object is not found.
This is with OJB rc4 at least.
Any help appreciated, Marko
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
