Top Description Inners Fields Constructors Methods
org.hibernate.engine.internal

public final Class TwoPhaseLoad

extends Object
Class Inheritance
Imports
java.io.Serializable, org.hibernate.AssertionFailure, .CacheMode, .HibernateException, .LockMode, org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer, org.hibernate.cache.spi.access.EntityDataAccess, org.hibernate.cache.spi.entry.CacheEntry, org.hibernate.engine.profile.Fetch, .FetchProfile, org.hibernate.engine.spi.EntityEntry, .EntityKey, .LoadQueryInfluencers, .PersistenceContext, .SessionEventListenerManager, .SessionFactoryImplementor, .SharedSessionContractImplementor, .Status, org.hibernate.event.service.spi.EventListenerGroup, .EventListenerRegistry, org.hibernate.event.spi.EventType, .PostLoadEvent, .PostLoadEventListener, .PreLoadEvent, .PreLoadEventListener, org.hibernate.internal.CoreMessageLogger, org.hibernate.persister.entity.EntityPersister, org.hibernate.pretty.MessageHelper, org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl, org.hibernate.proxy.HibernateProxy, org.hibernate.stat.internal.StatsHelper, org.hibernate.stat.spi.StatisticsImplementor, org.hibernate.type.EntityType, .Type, .TypeHelper, org.jboss.logging.Logger

Functionality relating to the Hibernate two-phase loading process, that may be reused by persisters that do not use the Loader framework
Author
Gavin King

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
TwoPhaseLoad.EntityResolver

Implementations determine how a to-one associations is resolved.

Field Summary

Modifier and TypeField and Description
private static final CoreMessageLogger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
addUninitializedCachedEntity(final EntityKey
The entity key
key
,
final Object
The entity instance
object
,
final EntityPersister
The entity persister
persister
,
final LockMode
The lock mode
lockMode
,
final Object
The version
version
,
final SharedSessionContractImplementor
The Session
session
)

Same as addUninitializedEntity, but here for an entity from the second level cache

public static void
addUninitializedEntity(final EntityKey
The entity key
key
,
final Object
The entity instance
object
,
final EntityPersister
The entity persister
persister
,
final LockMode
The lock mode
lockMode
,
final SharedSessionContractImplementor
The Session
session
)

Add an uninitialized instance of an entity class, as a placeholder to ensure object identity.

public static void
afterInitialize(final Object
The entity being loaded
entity
,
final SharedSessionContractImplementor
The Session
session
)

Perform the afterInitialize() step.

private static Boolean

Returns:

null if there is no overriding, true if it is overridden to eager and false if it is overridden to lazy
getOverridingEager
(final SharedSessionContractImplementor
session
session
,
final String
entity name
entityName
,
final String
association name
associationName
,
final Type
association type
associationType
,
final boolean
if debug log level enabled
isDebugEnabled
)

Check if eager of the association is overridden (i.e. skipping metamodel strategy), including (order sensitive):

  1. fetch graph
  2. fetch profile
public static void
initializeEntity(final Object
The entity being loaded
entity
,
final boolean
Is the entity being loaded as read-only
readOnly
,
final SharedSessionContractImplementor
The Session
session
,
final PreLoadEvent
The (re-used) pre-load event
preLoadEvent
)

Deprecated as a consequence of PreLoadEvent being deprecated.
Perform the second step of 2-phase load.
public static void
initializeEntity(final Object
The entity being loaded
entity
,
final boolean
Is the entity being loaded as read-only
readOnly
,
final SharedSessionContractImplementor
The Session
session
,
final PreLoadEvent
The (re-used) pre-load event
preLoadEvent
,
final TwoPhaseLoad.EntityResolver
the resolver used for to-one entity associations (not used when an entity is a bytecode-enhanced lazy entity)
entityResolver
)

Deprecated as a consequence of PreLoadEvent being deprecated.
Perform the second step of 2-phase load.
public static void
initializeEntityEntryLoadedState(final Object entity, final EntityEntry entityEntry, final SharedSessionContractImplementor session, final TwoPhaseLoad.EntityResolver entityResolver)

public static void
initializeEntityFromEntityEntryLoadedState(final Object entity, final EntityEntry entityEntry, final boolean readOnly, final SharedSessionContractImplementor session, final PreLoadEvent preLoadEvent)

Deprecated as a consequence of PreLoadEvent being deprecated.
private static Boolean
isEagerFetchProfile(SharedSessionContractImplementor session, String entityName, String associationName)

public static void
postHydrate(final EntityPersister
The persister for the hydrated entity
persister
,
final Serializable
The entity identifier
id
,
final Object[]
The entity values
values
,
final Object
The rowId for the entity
rowId
,
final Object
An optional instance for the entity being loaded
object
,
final LockMode
The lock mode
lockMode
,
final SharedSessionContractImplementor
The Session
session
)

Register the "hydrated" state of an entity instance, after the first step of 2-phase loading.

public static void
postLoad(final Object entity, final SharedSessionContractImplementor session, final PostLoadEvent postLoadEvent, final Iterable<PostLoadEventListener> postLoadEventListeners)

This method will be removed.
public static void
postLoad(final Object
The entity
entity
,
final SharedSessionContractImplementor
The Session
session
,
final PostLoadEvent
The (re-used) post-load event
postLoadEvent
)

PostLoad cannot occur during initializeEntity, as that call occurs *before* the Set collections are added to the persistence context by Loader.

private static boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGback to summary
private static final CoreMessageLogger LOG

Constructor Detail

TwoPhaseLoadback to summary
private TwoPhaseLoad()

Method Detail

addUninitializedCachedEntityback to summary
public static void addUninitializedCachedEntity(final EntityKey key, final Object object, final EntityPersister persister, final LockMode lockMode, final Object version, final SharedSessionContractImplementor session)

Same as addUninitializedEntity, but here for an entity from the second level cache

Parameters
key:EntityKey

The entity key

object:Object

The entity instance

persister:EntityPersister

The entity persister

lockMode:LockMode

The lock mode

version:Object

The version

session:SharedSessionContractImplementor

The Session

addUninitializedEntityback to summary
public static void addUninitializedEntity(final EntityKey key, final Object object, final EntityPersister persister, final LockMode lockMode, final SharedSessionContractImplementor session)

Add an uninitialized instance of an entity class, as a placeholder to ensure object identity. Must be called before postHydrate(). Create a "temporary" entry for a newly instantiated entity. The entity is uninitialized, but we need the mapping from id to instance in order to guarantee uniqueness.

Parameters
key:EntityKey

The entity key

object:Object

The entity instance

persister:EntityPersister

The entity persister

lockMode:LockMode

The lock mode

session:SharedSessionContractImplementor

The Session

afterInitializeback to summary
public static void afterInitialize(final Object entity, final SharedSessionContractImplementor session)

Perform the afterInitialize() step. This needs to be done after the collections have been properly initialized thus a separate step.

Parameters
entity:Object

The entity being loaded

session:SharedSessionContractImplementor

The Session

getOverridingEagerback to summary
private static Boolean getOverridingEager(final SharedSessionContractImplementor session, final String entityName, final String associationName, final Type associationType, final boolean isDebugEnabled)

Check if eager of the association is overridden (i.e. skipping metamodel strategy), including (order sensitive):

  1. fetch graph
  2. fetch profile
Parameters
session:SharedSessionContractImplementor

session

entityName:String

entity name

associationName:String

association name

associationType:Type

association type

isDebugEnabled:boolean

if debug log level enabled

Returns:Boolean

null if there is no overriding, true if it is overridden to eager and false if it is overridden to lazy

initializeEntityback to summary
public static void initializeEntity(final Object entity, final boolean readOnly, final SharedSessionContractImplementor session, final PreLoadEvent preLoadEvent)

Deprecated

as a consequence of PreLoadEvent being deprecated. See corresponding docs for further information.

Perform the second step of 2-phase load. Fully initialize the entity instance.

After processing a JDBC result set, we "resolve" all the associations between the entities which were instantiated and had their state "hydrated" into an array

Parameters
entity:Object

The entity being loaded

readOnly:boolean

Is the entity being loaded as read-only

session:SharedSessionContractImplementor

The Session

preLoadEvent:PreLoadEvent

The (re-used) pre-load event

initializeEntityback to summary
public static void initializeEntity(final Object entity, final boolean readOnly, final SharedSessionContractImplementor session, final PreLoadEvent preLoadEvent, final TwoPhaseLoad.EntityResolver entityResolver)

Deprecated

as a consequence of PreLoadEvent being deprecated. See corresponding docs for further information.

Perform the second step of 2-phase load. Fully initialize the entity instance.

After processing a JDBC result set, we "resolve" all the associations between the entities which were instantiated and had their state "hydrated" into an array

Parameters
entity:Object

The entity being loaded

readOnly:boolean

Is the entity being loaded as read-only

session:SharedSessionContractImplementor

The Session

preLoadEvent:PreLoadEvent

The (re-used) pre-load event

entityResolver:TwoPhaseLoad.EntityResolver

the resolver used for to-one entity associations (not used when an entity is a bytecode-enhanced lazy entity)

initializeEntityEntryLoadedStateback to summary
public static void initializeEntityEntryLoadedState(final Object entity, final EntityEntry entityEntry, final SharedSessionContractImplementor session, final TwoPhaseLoad.EntityResolver entityResolver) throws HibernateException
initializeEntityFromEntityEntryLoadedStateback to summary
public static void initializeEntityFromEntityEntryLoadedState(final Object entity, final EntityEntry entityEntry, final boolean readOnly, final SharedSessionContractImplementor session, final PreLoadEvent preLoadEvent) throws HibernateException

Deprecated

as a consequence of PreLoadEvent being deprecated. See corresponding docs for further information.

isEagerFetchProfileback to summary
private static Boolean isEagerFetchProfile(SharedSessionContractImplementor session, String entityName, String associationName)
postHydrateback to summary
public static void postHydrate(final EntityPersister persister, final Serializable id, final Object[] values, final Object rowId, final Object object, final LockMode lockMode, final SharedSessionContractImplementor session)

Register the "hydrated" state of an entity instance, after the first step of 2-phase loading. Add the "hydrated state" (an array) of an uninitialized entity to the session. We don't try to resolve any associations yet, because there might be other entities waiting to be read from the JDBC result set we are currently processing

Parameters
persister:EntityPersister

The persister for the hydrated entity

id:Serializable

The entity identifier

values:Object[]

The entity values

rowId:Object

The rowId for the entity

object:Object

An optional instance for the entity being loaded

lockMode:LockMode

The lock mode

session:SharedSessionContractImplementor

The Session

postLoadback to summary
public static void postLoad(final Object entity, final SharedSessionContractImplementor session, final PostLoadEvent postLoadEvent, final Iterable<PostLoadEventListener> postLoadEventListeners)

This method will be removed.

Annotations
@Deprecated
postLoadback to summary
public static void postLoad(final Object entity, final SharedSessionContractImplementor session, final PostLoadEvent postLoadEvent)

PostLoad cannot occur during initializeEntity, as that call occurs *before* the Set collections are added to the persistence context by Loader. Without the split, LazyInitializationExceptions can occur in the Entity's postLoad if it acts upon the collection. HHH-6043

Parameters
entity:Object

The entity

session:SharedSessionContractImplementor

The Session

postLoadEvent:PostLoadEvent

The (re-used) post-load event

useMinimalPutsback to summary
private static boolean useMinimalPuts(SharedSessionContractImplementor session, EntityEntry entityEntry)
org.hibernate.engine.internal back to summary

public Interface TwoPhaseLoad.EntityResolver


Implementations determine how a to-one associations is resolved.
See Also
initializeEntity(Object, boolean, SharedSessionContractImplementor, PreLoadEvent, EntityResolver)

Field Summary

Modifier and TypeField and Description
public static final TwoPhaseLoad.EntityResolver

Method Summary

Modifier and TypeMethod and Description
public Object
resolve(EntityType entityType, Object value, SharedSessionContractImplementor session, Object owner, Boolean overridingEager)

Field Detail

DEFAULTback to summary
public static final TwoPhaseLoad.EntityResolver DEFAULT

Method Detail

resolveback to summary
public Object resolve(EntityType entityType, Object value, SharedSessionContractImplementor session, Object owner, Boolean overridingEager)