Top Description Methods
org.hibernate.proxy

public Interface LazyInitializer

Known Direct Implementers
org.hibernate.proxy.AbstractLazyInitializer
Imports
java.io.Serializable, org.hibernate.HibernateException, org.hibernate.engine.spi.SharedSessionContractImplementor

Handles fetching of the underlying entity for a proxy
Authors
Gavin King, Steve Ebersole

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

The entity-name.
getEntityName
()

The entity-name of the entity our owning proxy represents.

public Serializable

Returns:

The identifier value.
getIdentifier
()

Retrieve the identifier value for the entity our owning proxy represents.

public Object

Returns:

The underlying target entity.
getImplementation
()

Return the underlying persistent object, initializing if necessary

public Object

Returns:

The target, or null.
getImplementation
(SharedSessionContractImplementor
The session to check
session
)

Return the underlying persistent object in the given session, or null if not contained in this session's persistence context.

public default Serializable

Returns:

The identifier value.
getInternalIdentifier
()

Retrieve the identifier value for the entity our owning proxy represents.

public Class<T>

Returns:

The actual entity class.
getPersistentClass
()

Get the actual class of the entity.

public SharedSessionContractImplementor

Returns:

The associated session.
getSession
()

Get the session to which this proxy is associated, or null if it is not attached.

public void
initialize()

Initialize the proxy, fetching the target entity if necessary.

public boolean

Returns:

true, if this proxy is read-only; false, otherwise
isReadOnly
()

Is the proxy read-only?

public boolean

Returns:

true, if the setting is available false, if the proxy is detached or its associated session is closed
isReadOnlySettingAvailable
()

Is the proxy's read-only/modifiable setting available?

public boolean

Returns:

True if uninitialized; false otherwise.
isUninitialized
()

Is the proxy uninitialized?

public boolean
public void
setIdentifier(Serializable
The identifier value.
id
)

Set the identifier value for the entity our owning proxy represents.

public void
setImplementation(Object
The proxy target (the actual entity being proxied).
target
)

Initialize the proxy manually by injecting its target.

public void
setReadOnly(boolean
if true, the associated proxy is made read-only; if false, the associated proxy is made modifiable.
readOnly
)

Set an associated modifiable proxy to read-only mode, or a read-only proxy to modifiable mode.

public void
setSession(SharedSessionContractImplementor
The session
session
)

Associate the proxy with the given session.

public void
setUnwrap(boolean unwrap)

public void
unsetSession()

Unset this initializer's reference to session.

Method Detail

getEntityNameback to summary
public String getEntityName()

The entity-name of the entity our owning proxy represents.

Returns:String

The entity-name.

getIdentifierback to summary
public Serializable getIdentifier()

Retrieve the identifier value for the entity our owning proxy represents. When JPA proxy compliance is enabled the proxy is initialized.

Returns:Serializable

The identifier value.

getImplementationback to summary
public Object getImplementation()

Return the underlying persistent object, initializing if necessary

Returns:Object

The underlying target entity.

getImplementationback to summary
public Object getImplementation(SharedSessionContractImplementor session) throws HibernateException

Return the underlying persistent object in the given session, or null if not contained in this session's persistence context.

Parameters
session:SharedSessionContractImplementor

The session to check

Returns:Object

The target, or null.

Exceptions
HibernateException:
Indicates problem locating the target.
getInternalIdentifierback to summary
public default Serializable getInternalIdentifier()

Retrieve the identifier value for the entity our owning proxy represents.

Returns:Serializable

The identifier value.

getPersistentClassback to summary
public Class<T> getPersistentClass()

Get the actual class of the entity. Generally, getEntityName() should be used instead.

Returns:Class<T>

The actual entity class.

getSessionback to summary
public SharedSessionContractImplementor getSession()

Get the session to which this proxy is associated, or null if it is not attached.

Returns:SharedSessionContractImplementor

The associated session.

initializeback to summary
public void initialize() throws HibernateException

Initialize the proxy, fetching the target entity if necessary.

Exceptions
HibernateException:
Indicates a problem initializing the proxy.
isReadOnlyback to summary
public 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:boolean

true, if this proxy is read-only; false, otherwise

Exceptions
TransientObjectException:
if the proxy is detached (getSession() == null)
SessionException:
if the proxy is associated with a session that is closed
See Also
org.hibernate.proxy.LazyInitializer#isReadOnlySettingAvailable(), org.hibernate.Session#isReadOnly(Object entityOrProxy)
isReadOnlySettingAvailableback to summary
public boolean isReadOnlySettingAvailable()

Is the proxy's read-only/modifiable setting available?

Returns:boolean

true, if the setting is available false, if the proxy is detached or its associated session is closed

isUninitializedback to summary
public boolean isUninitialized()

Is the proxy uninitialized?

Returns:boolean

True if uninitialized; false otherwise.

isUnwrapback to summary
public boolean isUnwrap()
setIdentifierback to summary
public void setIdentifier(Serializable id)

Set the identifier value for the entity our owning proxy represents.

Parameters
id:Serializable

The identifier value.

setImplementationback to summary
public void setImplementation(Object target)

Initialize the proxy manually by injecting its target.

Parameters
target:Object

The proxy target (the actual entity being proxied).

setReadOnlyback to summary
public 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:boolean

if true, the associated proxy is made read-only; if false, the associated proxy is made modifiable.

Exceptions
TransientObjectException:
if the proxy is not association with a session
SessionException:
if the proxy is associated with a session that is closed
See Also
org.hibernate.Session#setReadOnly(Object entityOrProxy, boolean readOnly)
setSessionback to summary
public void setSession(SharedSessionContractImplementor session) throws HibernateException

Associate the proxy with the given session.

Care should be given to make certain that the proxy is added to the session's persistence context as well to maintain the symmetry of the association. That must be done separately as this method simply sets an internal reference. We do also check that if there is already an associated session that the proxy reference was removed from that previous session's persistence context.

Parameters
session:SharedSessionContractImplementor

The session

Exceptions
HibernateException:
Indicates that the proxy was still contained in the persistence context of the "previous session".
setUnwrapback to summary
public void setUnwrap(boolean unwrap)
unsetSessionback to summary
public 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 org.hibernate.Session#evict and org.hibernate.Session#clear processing; most other use-cases should call setSession instead.