Class AbstractLazyInitializer
- All Implemented Interfaces:
LazyInitializer
- Direct Known Subclasses:
BasicLazyInitializer
,MapLazyInitializer
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractLazyInitializer
(String entityName, Object id, SharedSessionContractImplementor session) Main constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal String
The entity-name of the entity our owning proxy represents.final Object
Retrieve the identifier value for the entity our owning proxy represents, without initializing the proxy.final Object
Return the underlying persistent object, initializing if necessaryfinal Object
Return the underlying persistent object in the given session, or null if not contained in this session's persistence context.Get the actual name of the entity, possibly initializing the entity if it has subclasses.final Object
Retrieve the identifier value for the entity our owning proxy represents.Get the session to which this proxy is associated, or null if it is not attached.protected String
Get the session factory name.protected String
Get the session factory UUID.protected final Object
Getter for property "target".final void
Initialize the proxy, fetching the target entity if necessary.final void
Attempt to initialize the proxy without loading anything from the database.protected boolean
Get whether the proxy can load data even if it's not attached to a session with an ongoing transaction.protected final boolean
Getter for property 'connectedToSession'.final boolean
Is the proxy read-only?final Boolean
Get the read-only/modifiable setting that should be put in effect when it is attached to a session.final boolean
Is the proxy's read-only/modifiable setting available?final boolean
Is the proxy uninitialized?boolean
isUnwrap()
protected void
protected void
Initialize internal state based on the currently attached session, in order to be ready to load data even after the proxy is detached from the session.final void
setIdentifier
(Object id) Set the identifier value for the entity our owning proxy represents.final void
setImplementation
(Object target) Initialize the proxy manually by injecting its target.final void
setReadOnly
(boolean readOnly) Set an associated modifiable proxy to read-only mode, or a read-only proxy to modifiable mode.final void
Associate the proxy with the given session.void
setUnwrap
(boolean unwrap) final void
Unset this initializer's reference to session.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.hibernate.proxy.LazyInitializer
getImplementationClass, getPersistentClass
-
Constructor Details
-
Method Details
-
getEntityName
Description copied from interface:LazyInitializer
The entity-name of the entity our owning proxy represents.- Specified by:
getEntityName
in interfaceLazyInitializer
- Returns:
- The entity-name.
-
getInternalIdentifier
Description copied from interface:LazyInitializer
Retrieve the identifier value for the entity our owning proxy represents.- Specified by:
getInternalIdentifier
in interfaceLazyInitializer
- Returns:
- The identifier value.
-
getIdentifier
Description copied from interface:LazyInitializer
Retrieve the identifier value for the entity our owning proxy represents, without initializing the proxy.When JPA proxy compliance is enabled the proxy is initialized.
- Specified by:
getIdentifier
in interfaceLazyInitializer
- Returns:
- The identifier value.
-
setIdentifier
Description copied from interface:LazyInitializer
Set the identifier value for the entity our owning proxy represents.- Specified by:
setIdentifier
in interfaceLazyInitializer
- Parameters:
id
- The identifier value.
-
isUninitialized
public final boolean isUninitialized()Description copied from interface:LazyInitializer
Is the proxy uninitialized?- Specified by:
isUninitialized
in interfaceLazyInitializer
- Returns:
- True if uninitialized; false otherwise.
- See Also:
-
getSession
Description copied from interface:LazyInitializer
Get the session to which this proxy is associated, or null if it is not attached.- Specified by:
getSession
in interfaceLazyInitializer
- Returns:
- The associated session.
-
unsetSession
public final void unsetSession()Description copied from interface:LazyInitializer
Unset this initializer's reference to session. It is assumed that the caller is also taking care or cleaning up the owning proxy's reference in the persistence context.Generally speaking this is intended to be called only during
Session.evict(java.lang.Object)
andSession.clear()
processing; most other use-cases should callLazyInitializer.setSession(org.hibernate.engine.spi.SharedSessionContractImplementor)
instead.- Specified by:
unsetSession
in interfaceLazyInitializer
-
initialize
Description copied from interface:LazyInitializer
Initialize the proxy, fetching the target entity if necessary.- Specified by:
initialize
in interfaceLazyInitializer
- Throws:
HibernateException
- Indicates a problem initializing the proxy.- See Also:
-
permissiveInitialization
protected void permissiveInitialization() -
initializeWithoutLoadIfPossible
public final void initializeWithoutLoadIfPossible()Attempt to initialize the proxy without loading anything from the database.This will only have an effect if the proxy is still attached to a session, and the entity being proxied has been loaded and added to the persistence context of that session since the proxy was created.
-
prepareForPossibleLoadingOutsideTransaction
protected void prepareForPossibleLoadingOutsideTransaction()Initialize internal state based on the currently attached session, in order to be ready to load data even after the proxy is detached from the session. -
isConnectedToSession
protected final boolean isConnectedToSession()Getter for property 'connectedToSession'.- Returns:
- Value for property 'connectedToSession'.
-
getImplementation
Description copied from interface:LazyInitializer
Return the underlying persistent object, initializing if necessary- Specified by:
getImplementation
in interfaceLazyInitializer
- Returns:
- The underlying target entity.
-
setImplementation
Description copied from interface:LazyInitializer
Initialize the proxy manually by injecting its target.- Specified by:
setImplementation
in interfaceLazyInitializer
- Parameters:
target
- The proxy target (the actual entity being proxied).
-
getImplementationEntityName
Description copied from interface:LazyInitializer
Get the actual name of the entity, possibly initializing the entity if it has subclasses.- Specified by:
getImplementationEntityName
in interfaceLazyInitializer
- Returns:
- The actual entity name.
-
getTarget
Getter for property "target".Same as
getImplementation()
except that this method will not force initialization.- Returns:
- Value for property "target".
-
isReadOnlySettingAvailable
public final boolean isReadOnlySettingAvailable()Description copied from interface:LazyInitializer
Is the proxy's read-only/modifiable setting available?- Specified by:
isReadOnlySettingAvailable
in interfaceLazyInitializer
- Returns:
- true, if the setting is available false, if the proxy is detached or its associated session is closed
-
isReadOnly
public final boolean isReadOnly()Description copied from interface:LazyInitializer
Is the proxy read-only?The read-only/modifiable setting is not available when the proxy is detached or its associated session is closed.
To check if the read-only/modifiable setting is available:
- Specified by:
isReadOnly
in interfaceLazyInitializer
- Returns:
- true, if this proxy is read-only; false, otherwise
- See Also:
-
setReadOnly
public final void setReadOnly(boolean readOnly) Description copied from interface:LazyInitializer
Set an associated modifiable proxy to read-only mode, or a read-only proxy to modifiable mode. If the proxy is currently initialized, its implementation will be set to the same mode; otherwise, when the proxy is initialized, its implementation will have the same read-only/ modifiable setting as the proxy. In read-only mode, no snapshot is maintained and the instance is never dirty checked.If the associated proxy already has the specified read-only/modifiable setting, then this method does nothing.
- Specified by:
setReadOnly
in interfaceLazyInitializer
- Parameters:
readOnly
- if true, the associated proxy is made read-only; if false, the associated proxy is made modifiable.- See Also:
-
isReadOnlyBeforeAttachedToSession
Get the read-only/modifiable setting that should be put in effect when it is attached to a session.This method should only be called during serialization when read-only/modifiable setting is not available, that is, if
isReadOnlySettingAvailable() == false
- Returns:
null
, if the default setting should be used;true
, for read-only;false
, for modifiable- Throws:
IllegalStateException
- ifisReadOnlySettingAvailable() == true
-
isAllowLoadOutsideTransaction
protected boolean isAllowLoadOutsideTransaction()Get whether the proxy can load data even if it's not attached to a session with an ongoing transaction.This method should only be called during serialization, and only makes sense after a call to
prepareForPossibleLoadingOutsideTransaction()
.- Returns:
true
if out-of-transaction loads are allowed,false
otherwise.
-
getSessionFactoryUuid
Get the session factory UUID.This method should only be called during serialization, and only makes sense after a call to
prepareForPossibleLoadingOutsideTransaction()
.- Returns:
- the session factory UUID.
-
getSessionFactoryName
Get the session factory name.This method should only be called during serialization, and only makes sense after a call to
prepareForPossibleLoadingOutsideTransaction()
.- Returns:
- the session factory name.
-
isUnwrap
public boolean isUnwrap()- Specified by:
isUnwrap
in interfaceLazyInitializer
-
setUnwrap
public void setUnwrap(boolean unwrap) - Specified by:
setUnwrap
in interfaceLazyInitializer
-