org.hibernate.proxy
Interface LazyInitializer

All Known Implementing Classes:
AbstractLazyInitializer, BasicLazyInitializer, CGLIBLazyInitializer, Dom4jLazyInitializer, JavassistLazyInitializer, MapLazyInitializer

public interface LazyInitializer

Handles fetching of the underlying entity for a proxy

Author:
Gavin King, Steve Ebersole

Method Summary
 String getEntityName()
          The entity-name of the entity our owning proxy represents.
 Serializable getIdentifier()
          Retrieve the identifier value for the enity our owning proxy represents.
 Object getImplementation()
          Return the underlying persistent object, initializing if necessary
 Object getImplementation(SessionImplementor session)
          Return the underlying persistent object in the given session, or null if not contained in this session's persistence context.
 Class getPersistentClass()
          Get the actual class of the entity.
 SessionImplementor getSession()
          Get the session to which this proxy is associated, or null if it is not attached.
 void initialize()
          Initialize the proxy, fetching the target entity if necessary.
 boolean isUninitialized()
          Is the proxy uninitialzed?
 boolean isUnwrap()
           
 void setIdentifier(Serializable id)
          Set the identifier value for the enity our owning proxy represents.
 void setImplementation(Object target)
          Initialize the proxy manually by injecting its target.
 void setSession(SessionImplementor session)
          Associate the proxy with the given session.
 void setUnwrap(boolean unwrap)
           
 void unsetSession()
          Unset this initializer's reference to session.
 

Method Detail

initialize

void initialize()
                throws HibernateException
Initialize the proxy, fetching the target entity if necessary.

Throws:
HibernateException - Indicates a problem initializing the proxy.

getIdentifier

Serializable getIdentifier()
Retrieve the identifier value for the enity our owning proxy represents.

Returns:
The identifier value.

setIdentifier

void setIdentifier(Serializable id)
Set the identifier value for the enity 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 uninitialzed?

Returns:
True if uninitialized; false otherwise.

getImplementation

Object getImplementation()
Return the underlying persistent object, initializing if necessary

Returns:
The underlying target entity.

getImplementation

Object getImplementation(SessionImplementor 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 - The session to check
Returns:
The target, or null.
Throws:
HibernateException - Indicates problem locating the target.

setImplementation

void setImplementation(Object target)
Initialize the proxy manually by injecting its target.

Parameters:
target - The proxy target (the actual entity being proxied).

getSession

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

Returns:
The associated session.

setSession

void setSession(SessionImplementor 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 symetry of the association. That must be done seperately 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 contet.

Parameters:
session - The session
Throws:
HibernateException - Indicates that the proxy was still contained in the persistence context of the "previous 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) and Session.clear() processing; most other use-cases should call setSession(org.hibernate.engine.SessionImplementor) instead.


setUnwrap

void setUnwrap(boolean unwrap)

isUnwrap

boolean isUnwrap()


Copyright © null-null Red Hat Middleware, LLC. All Rights Reserved