Package org.hibernate.proxy
Interface LazyInitializer
- All Known Implementing Classes:
AbstractLazyInitializer
,BasicLazyInitializer
,ByteBuddyInterceptor
,MapLazyInitializer
public interface LazyInitializer
Handles fetching of the underlying entity for a proxy.
-
Method Summary
Modifier and TypeMethodDescriptionThe entity-name of the entity our owning proxy represents.Retrieve the identifier value for the entity our owning proxy represents, without initializing the proxy.Return the underlying persistent object, initializing if necessaryReturn the underlying persistent object in the given session, or null if not contained in this session's persistence context.Class<?>
Get the actual class of the entity, possibly initializing the entity if it has subclasses.Get the actual name of the entity, possibly initializing the entity if it has subclasses.default Object
Retrieve the identifier value for the entity our owning proxy represents.Class<?>
Get the actual class of the entity.Get the session to which this proxy is associated, or null if it is not attached.void
Initialize the proxy, fetching the target entity if necessary.boolean
Is the proxy read-only?boolean
Is the proxy's read-only/modifiable setting available?boolean
Is the proxy uninitialized?boolean
isUnwrap()
void
setIdentifier
(Object id) Set the identifier value for the entity our owning proxy represents.void
setImplementation
(Object target) Initialize the proxy manually by injecting its target.void
setReadOnly
(boolean readOnly) Set an associated modifiable proxy to read-only mode, or a read-only proxy to modifiable mode.void
Associate the proxy with the given session.void
setUnwrap
(boolean unwrap) void
Unset this initializer's reference to session.
-
Method Details
-
initialize
Initialize the proxy, fetching the target entity if necessary.- Throws:
HibernateException
- Indicates a problem initializing the proxy.- See Also:
-
getInternalIdentifier
Retrieve the identifier value for the entity our owning proxy represents.- Returns:
- The identifier value.
-
getIdentifier
Object getIdentifier()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.
- Returns:
- The identifier value.
-
setIdentifier
Set the identifier value for the entity our owning proxy represents.- Parameters:
id
- The identifier value.
-
getEntityName
String getEntityName()The entity-name of the entity our owning proxy represents.- Returns:
- The entity-name.
-
getPersistentClass
Class<?> getPersistentClass()Get the actual class of the entity. Generally,getEntityName()
should be used instead.- Returns:
- The actual entity class.
-
isUninitialized
boolean isUninitialized()Is the proxy uninitialized?- Returns:
- True if uninitialized; false otherwise.
- See Also:
-
getImplementation
Object getImplementation()Return the underlying persistent object, initializing if necessary- Returns:
- The underlying target entity.
-
setImplementation
Initialize the proxy manually by injecting its target.- Parameters:
target
- The proxy target (the actual entity being proxied).
-
getImplementationClass
Class<?> getImplementationClass()Get the actual class of the entity, possibly initializing the entity if it has subclasses.- Returns:
- The actual entity class.
- Since:
- 6.3
-
getImplementationEntityName
String getImplementationEntityName()Get the actual name of the entity, possibly initializing the entity if it has subclasses.- Returns:
- The actual entity name.
- Since:
- 6.3
-
isReadOnlySettingAvailable
boolean isReadOnlySettingAvailable()Is the proxy's read-only/modifiable setting available?- Returns:
- true, if the setting is available false, if the proxy is detached or its associated session is closed
-
isReadOnly
boolean isReadOnly()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:
- Returns:
- true, if this proxy is read-only; false, otherwise
- Throws:
TransientObjectException
- if the proxy is detached (getSession() == null)SessionException
- if the proxy is associated with a session that is closed- See Also:
-
setReadOnly
void setReadOnly(boolean readOnly) 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.
- Parameters:
readOnly
- if true, the associated proxy is made read-only; if false, the associated proxy is made modifiable.- Throws:
TransientObjectException
- if the proxy is not association with a sessionSessionException
- if the proxy is associated with a session that is closed- See Also:
-
getSession
SharedSessionContractImplementor getSession()Get the session to which this proxy is associated, or null if it is not attached.- Returns:
- The associated session.
-
unsetSession
void unsetSession()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 callsetSession(org.hibernate.engine.spi.SharedSessionContractImplementor)
instead. -
setUnwrap
void setUnwrap(boolean unwrap) -
isUnwrap
boolean isUnwrap()
-