use of org.hibernate.cache.spi.entry.ReferenceCacheEntryImpl in project hibernate-orm by hibernate.
the class Loader method instanceNotYetLoaded.
/**
* The entity instance is not in the session cache
*/
private Object instanceNotYetLoaded(final ResultSet rs, final int i, final Loadable persister, final String rowIdAlias, final EntityKey key, final LockMode lockMode, final EntityKey optionalObjectKey, final Object optionalObject, final List hydratedObjects, final SharedSessionContractImplementor session) throws HibernateException, SQLException {
final String instanceClass = getInstanceClass(rs, i, persister, key.getIdentifier(), session);
// see if the entity defines reference caching, and if so use the cached reference (if one).
if (session.getCacheMode().isGetEnabled() && persister.canUseReferenceCacheEntries()) {
final EntityDataAccess cache = persister.getCacheAccessStrategy();
final Object ck = cache.generateCacheKey(key.getIdentifier(), persister, session.getFactory(), session.getTenantIdentifier());
final Object cachedEntry = CacheHelper.fromSharedCache(session, ck, cache);
if (cachedEntry != null) {
CacheEntry entry = (CacheEntry) persister.getCacheEntryStructure().destructure(cachedEntry, factory);
return ((ReferenceCacheEntryImpl) entry).getReference();
}
}
final Object object;
if (optionalObjectKey != null && key.equals(optionalObjectKey)) {
// its the given optional object
object = optionalObject;
} else {
// instantiate a new instance
object = session.instantiate(instanceClass, key.getIdentifier());
}
// need to hydrate it.
// grab its state from the ResultSet and keep it in the Session
// (but don't yet initialize the object itself)
// note that we acquire LockMode.READ even if it was not requested
LockMode acquiredLockMode = lockMode == LockMode.NONE ? LockMode.READ : lockMode;
loadFromResultSet(rs, i, object, instanceClass, key, rowIdAlias, acquiredLockMode, persister, session);
// materialize associations (and initialize the object) later
hydratedObjects.add(object);
return object;
}
Aggregations