Class AbstractLazyInitializer

  • All Implemented Interfaces:
    Direct Known Subclasses:
    BasicLazyInitializer, MapLazyInitializer

    public abstract class AbstractLazyInitializer
    extends Object
    implements LazyInitializer
    Convenience base class for lazy initialization handlers. Centralizes the basic plumbing of doing lazy initialization freeing subclasses to acts as essentially adapters to their intended entity mode and/or proxy generation strategy.
    • Method Detail

      • getEntityName

        public final String getEntityName()
        Description copied from interface: LazyInitializer
        The entity-name of the entity our owning proxy represents.
        Specified by:
        getEntityName in interface LazyInitializer
        The entity-name.
      • getIdentifier

        public final Serializable getIdentifier()
        Description copied from interface: LazyInitializer
        Retrieve the identifier value for the entity our owning proxy represents. When JPA proxy compliance is enabled the proxy is initialized.
        Specified by:
        getIdentifier in interface LazyInitializer
        The identifier value.
      • setIdentifier

        public final void setIdentifier​(Serializable id)
        Description copied from interface: LazyInitializer
        Set the identifier value for the entity our owning proxy represents.
        Specified by:
        setIdentifier in interface LazyInitializer
        id - The identifier value.
      • isUninitialized

        public final boolean isUninitialized()
        Description copied from interface: LazyInitializer
        Is the proxy uninitialized?
        Specified by:
        isUninitialized in interface LazyInitializer
        True if uninitialized; false otherwise.
      • setSession

        public final void setSession​(SharedSessionContractImplementor s)
                              throws HibernateException
        Description copied from interface: LazyInitializer
        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.

        Specified by:
        setSession in interface LazyInitializer
        s - The session
        HibernateException - Indicates that the proxy was still contained in the persistence context of the "previous session".
      • permissiveInitialization

        protected void permissiveInitialization()
      • initializeWithoutLoadIfPossible

        public final void initializeWithoutLoadIfPossible()
        Attempt to initialize the proxy without loading anything from the database. This will only have any 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. This method only has any effect if SessionFactoryOptions.isInitializeLazyStateOutsideTransactionsEnabled() is true.
      • isConnectedToSession

        protected final boolean isConnectedToSession()
        Getter for property 'connectedToSession'.
        Value for property 'connectedToSession'.
      • getImplementation

        public final Object getImplementation()
        Description copied from interface: LazyInitializer
        Return the underlying persistent object, initializing if necessary
        Specified by:
        getImplementation in interface LazyInitializer
        The underlying target entity.
      • setImplementation

        public final void setImplementation​(Object target)
        Description copied from interface: LazyInitializer
        Initialize the proxy manually by injecting its target.
        Specified by:
        setImplementation in interface LazyInitializer
        target - The proxy target (the actual entity being proxied).
      • getTarget

        protected final Object getTarget()
        Getter for property 'target'.

        Same as getImplementation() except that this method will not force initialization.

        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 interface LazyInitializer
        true, if the setting is available false, if the proxy is detached or its associated session is closed
      • 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 interface LazyInitializer
        readOnly - if true, the associated proxy is made read-only; if false, the associated proxy is made modifiable.
        See Also:
        Session.setReadOnly(Object entityOrProxy, boolean readOnly)
      • isReadOnlyBeforeAttachedToSession

        public final Boolean isReadOnlyBeforeAttachedToSession()
        Get the read-only/modifiable setting that should be put in affect when it is attached to a session.

        This method should only be called during serialization when read-only/modifiable setting is not available (i.e., isReadOnlySettingAvailable() == false)

        null, if the default setting should be used; true, for read-only; false, for modifiable
        IllegalStateException - if isReadOnlySettingAvailable() == 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().
        true if out-of-transaction loads are allowed, false otherwise.
      • getSessionFactoryUuid

        protected String getSessionFactoryUuid()
        Get the session factory UUID. This method should only be called during serialization, and only makes sense after a call to prepareForPossibleLoadingOutsideTransaction().
        the session factory UUID.