* @return the loaded Object
*/
public Persistable loadObject(Persistable persistable, boolean forceReloadFromDB) {
if (persistable == null) throw new AssertException("persistable must not be null");
beginTransaction(persistable);
Persistable ret;
Class theClass = persistable.getClass();
if (forceReloadFromDB) {
// we want to reload it from the database.
// there are 3 scenarios possible:
// a) the object is not yet in the hibernate cache
// b) the object is in the hibernate cache
// c) the object is detached and there is an object with the same id in the hibernate cache
if (contains(persistable)) {
// case b - then we can use evict and load
getDBManager().evict(persistable);
return (Persistable) loadObject(theClass, persistable.getKey());
} else {
// case a or c - unfortunatelly we can't distinguish these two cases
// and session.refresh(Object) doesn't work.
// the only scenario that works is load/evict/load
Persistable attachedObj = (Persistable) loadObject(theClass, persistable.getKey());
getDBManager().evict(attachedObj);
return (Persistable) loadObject(theClass, persistable.getKey());
}
} else if (!contains(persistable)) {
// forceReloadFromDB is false - hence it is OK to take it from the cache if it would be there