Object domainObject = null;
if (primaryKey == null) {
this.activeCacheKey = null;
return null;
}
CacheKey cacheKey = session.getIdentityMapAccessorInstance().getCacheKeyForObject(primaryKey, descriptor.getJavaClass(), descriptor, true);
if (cacheKey != null) {
if (cacheKey.acquireReadLockNoWait()) {
domainObject = cacheKey.getObject();
cacheKey.releaseReadLock();
} else {
if (!mergeManager.isTransitionedToDeferredLocks()) {
session.getIdentityMapAccessorInstance().getWriteLockManager().transitionToDeferredLocks(mergeManager);
}
cacheKey.acquireDeferredLock();
domainObject = cacheKey.getObject();
int tries = 0;
while (domainObject == null) {
++tries;
if (tries > MAX_TRIES){
session.getParent().log(SessionLog.SEVERE, SessionLog.CACHE, "entity_not_available_during_merge", new Object[]{descriptor.getJavaClassName(), cacheKey.getKey(), Thread.currentThread().getName(), cacheKey.getMutex().getActiveThread()});
break;
}
synchronized (cacheKey.getMutex()) {
if (cacheKey.isAcquired()) {
try {
cacheKey.getMutex().wait(10);
} catch (InterruptedException e) {
//ignore and return
}
}
domainObject = cacheKey.getObject();
}
}
cacheKey.releaseDeferredLock();
}
} else {
domainObject = mergeManager.registerExistingObjectOfReadOnlyClassInNestedTransaction(getUnitOfWorkClone(), descriptor, session);
// There is no need to get the cache key in this case because UOW is performing
// a nested UOW merge, and no locking occurs.