// If this is a UOW and modification queries have been executed, the cache cannot be trusted.
if (this.checkDatabaseIfInvalid && (session.isUnitOfWork() && ((UnitOfWorkImpl)session).shouldReadFromDB())) {
return null;
}
CacheKey cacheKey;
Class objectClass = object.getClass();
AbstractSession tempSession = session;
while (tempSession.isUnitOfWork()){ //could be nested lets check all UOWs
cacheKey = tempSession.getIdentityMapAccessorInstance().getCacheKeyForObjectForLock(primaryKey, objectClass, descriptor);
if (cacheKey != null) {
// If in the UOW cache it can't be invalid.
return Boolean.TRUE;
}
tempSession = ((UnitOfWorkImpl)tempSession).getParent();
}
// Did not find it registered in UOW so check main cache and check for invalidation.
cacheKey = tempSession.getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey,objectClass, descriptor);
if ((cacheKey != null)) {
// Assume that if there is a cachekey, object exists.
if (this.checkDatabaseIfInvalid) {
checkDescriptor(object, session);
if (getDescriptor().getCacheInvalidationPolicy().isInvalidated(cacheKey, System.currentTimeMillis())) {
return null;
}
}
Object objectFromCache = cacheKey.getObject();
if ((session.isUnitOfWork()) && ((UnitOfWorkImpl)session).wasDeleted(objectFromCache)) {
if (shouldCheckCacheForDoesExist()) {
return Boolean.FALSE;
}
} else {