Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.hibernate.engine.internal
Class StatefulPersistenceContext

    java.lang.Object
      org.hibernate.engine.internal.StatefulPersistenceContext

All Implemented Interfaces:
  PersistenceContext

    public class StatefulPersistenceContext

extends Object
implements PersistenceContext

A stateful implementation of the `PersistenceContext` contract meaning that we maintain this state throughout the life of the persistence context.

IMPL NOTE: There is meant to be a one-to-one correspondence between a `SessionImpl` and a PersistentContext. Event listeners and other Session collaborators then use the PersistentContext to drive their processing.

Nested Class Summary

Nested classes/interfaces inherited from interface org.hibernate.engine.spi.PersistenceContext
`PersistenceContext.NaturalIdHelper`

Field Summary
`static Object` | `NO_ROW`

Constructor Summary
`StatefulPersistenceContext(SessionImplementor session)` Constructs a PersistentContext, bound to the given session.

Method Summary
`void` | `addChildParent(Object child, Object parent)` Add a child/parent relation to cache for cascading op
`void` | `addCollectionHolder(PersistentCollection holder)` Register a `PersistentCollection` object for an array.
`void` | `addEntity(EntityKey key, Object entity)` Add a canonical mapping from entity key to entity instance
`void` | `addEntity(EntityUniqueKey euk, Object entity)` Add an entity to the cache by unique key
`EntityEntry` | `addEntity(Object entity, Status status, Object[] loadedState, EntityKey entityKey, Object version, LockMode lockMode, boolean existsInDatabase, EntityPersister persister, boolean disableVersionIncrement, boolean lazyPropertiesAreUnfetched)` Adds an entity to the internal caches.
`EntityEntry` | `addEntry(Object entity, Status status, Object[] loadedState, Object rowId, Serializable id, Object version, LockMode lockMode, boolean existsInDatabase, EntityPersister persister, boolean disableVersionIncrement, boolean lazyPropertiesAreUnfetched)` Generates an appropriate EntityEntry instance and adds it to the event source's internal caches.
`CollectionEntry` | `addInitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id)` add a collection we just pulled out of the cache (does not need initializing)
`void` | `addInitializedDetachedCollection(CollectionPersister collectionPersister, PersistentCollection collection)` add an (initialized) collection that was created by another session and passed into update() (ie.
`void` | `addNewCollection(CollectionPersister persister, PersistentCollection collection)` Add a new collection (ie.
`void` | `addNonLazyCollection(PersistentCollection collection)` Register a collection for non-lazy loading at the end of the two-phase load
`void` | `addNullProperty(EntityKey ownerKey, String propertyName)` Record the fact that the association belonging to the keyed entity is null.
`void` | `addProxy(EntityKey key, Object proxy)` Add a proxy to the session cache
`void` | `addUninitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id)` add a collection we just loaded up (still needs initializing)
`void` | `addUninitializedDetachedCollection(CollectionPersister persister, PersistentCollection collection)` add a detached uninitialized collection
`void` | `addUnownedCollection(CollectionKey key, PersistentCollection collection)` Add a collection which has no owner loaded
`void` | `afterLoad()` Call this after finishing a two-phase load
`void` | `afterTransactionCompletion()` Called after transactions end
`void` | `beforeLoad()` Call this before beginning a two-phase load
`void` | `checkUniqueness(EntityKey key, Object object)` Attempts to check whether the given key represents an entity already loaded within the current session.
`void` | `clear()` Clear the state of the persistence context
`boolean` | `containsCollection(PersistentCollection collection)` Is the given collection associated with this persistence context?
`boolean` | `containsEntity(EntityKey key)` Is there an entity with the given key in the persistence context
`boolean` | `containsProxy(Object entity)` Is the given proxy associated with this persistence context?
`int` | `decrementCascadeLevel()` Called after cascading
`static StatefulPersistenceContext` | `deserialize(ObjectInputStream ois, SessionImplementor session)`
`BatchFetchQueue` | `getBatchFetchQueue()` Get the `BatchFetchQueue`, instantiating one if necessary.
`Object[]` | `getCachedDatabaseSnapshot(EntityKey key)` Retrieve the cached database snapshot for the requested entity key.
`int` | `getCascadeLevel()` How deep are we cascaded?
`PersistentCollection` | `getCollection(CollectionKey collectionKey)` Get the collection instance associated with the `CollectionKey`
`Map` | `getCollectionEntries()` Get the mapping from collection instance to collection entry
`CollectionEntry` | `getCollectionEntry(PersistentCollection coll)` Get the collection entry for a persistent collection
`CollectionEntry` | `getCollectionEntryOrNull(Object collection)` Get the collection entry for a collection passed to filter, which might be a collection wrapper, an array, or an unwrapped collection.
`PersistentCollection` | `getCollectionHolder(Object array)` Get the `PersistentCollection` object for an array
`Object` | `getCollectionOwner(Serializable key, CollectionPersister collectionPersister)` Get the entity that owns this persistent collection
`Map` | `getCollectionsByKey()` Get the mapping from collection key to collection instance
`Object[]` | `getDatabaseSnapshot(Serializable id, EntityPersister persister)` Get the current state of the entity as known to the underlying database, or null if there is no corresponding row
`Map` | `getEntitiesByKey()` Get the mapping from key value to entity instance
`Object` | `getEntity(EntityKey key)` Get the entity instance associated with the given `EntityKey`
`Object` | `getEntity(EntityUniqueKey euk)` Get an entity cached by unique key
`Map` | `getEntityEntries()` Get the mapping from entity instance to entity entry
`EntityEntry` | `getEntry(Object entity)` Retrieve the EntityEntry representation of the given entity.
`Object` | `getIndexInOwner(String entity, String property, Object childEntity, Map mergeMap)` Search the persistence context for an index of the child object, given a collection role
`LoadContexts` | `getLoadContexts()` Retrieve this persistence context's managed load context.
`Serializable` | `getLoadedCollectionOwnerIdOrNull(PersistentCollection collection)` Get the ID for the entity that owned this persistent collection when it was loaded
`Object` | `getLoadedCollectionOwnerOrNull(PersistentCollection collection)` Get the entity that owned this persistent collection when it was loaded
`PersistenceContext.NaturalIdHelper` | `getNaturalIdHelper()` Access to the natural-id helper for this persistence context
`Object[]` | `getNaturalIdSnapshot(Serializable id, EntityPersister persister)` Get the values of the natural id fields as known to the underlying database, or null if the entity has no natural id or there is no corresponding row.
`HashSet` | `getNullifiableEntityKeys()` Retrieve the set of EntityKeys representing nullifiable references
`Serializable` | `getOwnerId(String entityName, String propertyName, Object childEntity, Map mergeMap)` Search `this` persistence context for an associated entity instance which is considered the "owner" of the given `childEntity`, and return that owner's id value.
`Map` | `getProxiesByKey()`
`Object` | `getProxy(EntityKey key)` Get an existing proxy by key
`SessionImplementor` | `getSession()` Get the session to which this persistence context is bound.
`Serializable` | `getSnapshot(PersistentCollection coll)` Get the snapshot of the pre-flush collection state
`boolean` | `hasNonReadOnlyEntities()`
`int` | `incrementCascadeLevel()` Called before cascading
`void` | `initializeNonLazyCollections()` Force initialization of all non-lazy collections encountered during the current two-phase load (actually, this is a no-op, unless this is the "outermost" load)
`boolean` | `isDefaultReadOnly()` Will entities and proxies that are loaded into this persistence context be made read-only by default? To determine the read-only/modifiable setting for a particular entity or proxy:
`boolean` | `isEntryFor(Object entity)` Is there an EntityEntry for this instance?
`boolean` | `isFlushing()` Is a flush cycle currently in process?
`boolean` | `isLoadFinished()` Is in a two-phase load?
`boolean` | `isPropertyNull(EntityKey ownerKey, String propertyName)` Is the association property belonging to the keyed entity null?
`boolean` | `isReadOnly(Object entityOrProxy)` Is the entity or proxy read-only? To determine the default read-only/modifiable setting used for entities and proxies that are loaded into the session use `Session.isDefaultReadOnly()`
`boolean` | `isStateless()`
`Object` | `narrowProxy(Object proxy, EntityPersister persister, EntityKey key, Object object)` If the existing proxy is insufficiently "narrow" (derived), instantiate a new proxy and overwrite the registration of the old one.
`Object` | `proxyFor(EntityPersister persister, EntityKey key, Object impl)` Return the existing proxy associated with the given `EntityKey`, or the third argument (the entity associated with the key) if no proxy exists.
`Object` | `proxyFor(Object impl)` Return the existing proxy associated with the given `EntityKey`, or the argument (the entity associated with the key) if no proxy exists.
`boolean` | `reassociateIfUninitializedProxy(Object value)` Takes the given object and, if it represents a proxy, reassociates it with this event source.
`void` | `reassociateProxy(Object value, Serializable id)` If a deleted entity instance is re-saved, and it has a proxy, we need to reset the identifier of the proxy
`void` | `registerInsertedKey(EntityPersister persister, Serializable id)` Register keys inserted during the current transaction
`void` | `removeChildParent(Object child)` Remove child/parent relation from cache
`PersistentCollection` | `removeCollectionHolder(Object array)` Remove the mapping of collection to holder during eviction of the owning entity
`Object` | `removeEntity(EntityKey key)` Remove an entity from the session cache, also clear up other state associated with the entity, all except for the `EntityEntry`
`EntityEntry` | `removeEntry(Object entity)` Remove an entity entry from the session cache
`Object` | `removeProxy(EntityKey key)` Remove a proxy from the session cache.
`void` | `replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey, Serializable generatedId)`
`void` | `serialize(ObjectOutputStream oos)` Used by the owning session to explicitly control serialization of the persistence context.
`void` | `setDefaultReadOnly(boolean defaultReadOnly)` Change the default for entities and proxies loaded into this persistence context from modifiable to read-only mode, or from modifiable to read-only mode.
`void` | `setEntryStatus(EntityEntry entry, Status status)` Set the status of an entry
`void` | `setFlushing(boolean flushing)` Called before and after the flushcycle
`void` | `setReadOnly(Object object, boolean readOnly)` Set an unmodified persistent object to read-only mode, or a read-only object to modifiable mode.
`String` | `toString()` Returns a string representation of the object.
`Object` | `unproxy(Object maybeProxy)` Get the entity instance underlying the given proxy, throwing an exception if the proxy is uninitialized.
`Object` | `unproxyAndReassociate(Object maybeProxy)` Possibly unproxy the given reference and reassociate it with the current session.
`PersistentCollection` | `useUnownedCollection(CollectionKey key)` Take ownership of a previously unowned collection, if one.
`boolean` | `wasInsertedDuringTransaction(EntityPersister persister, Serializable id)` Allows callers to check to see if the identified entity was inserted during the current transaction.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### NO_ROW

    public static final Object NO_ROW

Constructor Detail

### StatefulPersistenceContext

    public StatefulPersistenceContext(SessionImplementor session)

  Constructs a PersistentContext, bound to the given session.

  Parameters:
    `session` - The session "owning" this context.

Method Detail

### isStateless

    public boolean isStateless()

  Specified by:
    `isStateless` in interface `PersistenceContext`

### getSession

    public SessionImplementor getSession()

  Description copied from interface: `PersistenceContext`
  Get the session to which this persistence context is bound.

  Specified by:
    `getSession` in interface `PersistenceContext`
  Returns:
    The session.

### getLoadContexts

    public LoadContexts getLoadContexts()

  Description copied from interface: `PersistenceContext`
  Retrieve this persistence context's managed load context.

  Specified by:
    `getLoadContexts` in interface `PersistenceContext`
  Returns:
    The load context

### addUnownedCollection

    public void addUnownedCollection(CollectionKey key,
                                     PersistentCollection collection)

  Description copied from interface: `PersistenceContext`
  Add a collection which has no owner loaded

  Specified by:
    `addUnownedCollection` in interface `PersistenceContext`
  Parameters:
    `key` - The collection key under which to add the collection
    `collection` - The collection to add

### useUnownedCollection

    public PersistentCollection useUnownedCollection(CollectionKey key)

  Description copied from interface: `PersistenceContext`
  Take ownership of a previously unowned collection, if one. This method returns `null` if no such collection was previous added () or was previously removed.

  This should indicate the owner is being loaded and we are ready to "link" them.

  Specified by:
    `useUnownedCollection` in interface `PersistenceContext`
  Parameters:
    `key` - The collection key for which to locate a collection collection
  Returns:
    The unowned collection, or `null`

### getBatchFetchQueue

    public BatchFetchQueue getBatchFetchQueue()

  Description copied from interface: `PersistenceContext`
  Get the `BatchFetchQueue`, instantiating one if necessary.

  Specified by:
    `getBatchFetchQueue` in interface `PersistenceContext`
  Returns:
    The batch fetch queue in effect for this persistence context

### clear

    public void clear()

  Description copied from interface: `PersistenceContext`
  Clear the state of the persistence context

  Specified by:
    `clear` in interface `PersistenceContext`

### isDefaultReadOnly

    public boolean isDefaultReadOnly()

  Description copied from interface: `PersistenceContext`
  Will entities and proxies that are loaded into this persistence context be made read-only by default? To determine the read-only/modifiable setting for a particular entity or proxy:

  Specified by:
    `isDefaultReadOnly` in interface `PersistenceContext`
  Returns:
    true, loaded entities/proxies will be made read-only by default; false, loaded entities/proxies will be made modifiable by default.
  See Also:
    `PersistenceContext.isReadOnly(Object)`, `Session.isReadOnly(Object)`, `Session.isDefaultReadOnly()`

### setDefaultReadOnly

    public void setDefaultReadOnly(boolean defaultReadOnly)

  Description copied from interface: `PersistenceContext`
  Change the default for entities and proxies loaded into this persistence context from modifiable to read-only mode, or from modifiable to read-only mode. Read-only entities are not dirty-checked and snapshots of persistent state are not maintained. Read-only entities can be modified, but changes are not persisted. When a proxy is initialized, the loaded entity will have the same read-only/modifiable setting as the uninitialized proxy has, regardless of the persistence context's current setting. To change the read-only/modifiable setting for a particular entity or proxy that is already in this session: + * @see PersistenceContext#setReadOnly(Object,boolean)

  Specified by:
    `setDefaultReadOnly` in interface `PersistenceContext`
  Parameters:
    `defaultReadOnly` - true, the default for loaded entities/proxies is read-only; false, the default for loaded entities/proxies is modifiable
  See Also:
    `To override this session's read-only/modifiable setting for entities and proxies loaded by a Query:`, `Query.setReadOnly(boolean)`, `Session.setDefaultReadOnly(boolean)`

### hasNonReadOnlyEntities

    public boolean hasNonReadOnlyEntities()

  Specified by:
    `hasNonReadOnlyEntities` in interface `PersistenceContext`
  Returns:
    false if we know for certain that all the entities are read-only

### setEntryStatus

    public void setEntryStatus(EntityEntry entry,
                               Status status)

  Description copied from interface: `PersistenceContext`
  Set the status of an entry

  Specified by:
    `setEntryStatus` in interface `PersistenceContext`
  Parameters:
    `entry` - The entry for which to set the status
    `status` - The new status

### afterTransactionCompletion

    public void afterTransactionCompletion()

  Description copied from interface: `PersistenceContext`
  Called after transactions end

  Specified by:
    `afterTransactionCompletion` in interface `PersistenceContext`

### getDatabaseSnapshot

    public Object[] getDatabaseSnapshot(Serializable id,
                                        EntityPersister persister)
                                 throws HibernateException

  Get the current state of the entity as known to the underlying database, or null if there is no corresponding row

  Specified by:
    `getDatabaseSnapshot` in interface `PersistenceContext`
  Parameters:
    `id` - The identifier of the entity for which to grab a snapshot
    `persister` - The persister of the entity.
  Returns:
    The entity's (non-cached) snapshot
  Throws:
    `HibernateException`
  See Also:
    `PersistenceContext.getCachedDatabaseSnapshot(org.hibernate.engine.spi.EntityKey)`

### getNaturalIdSnapshot

    public Object[] getNaturalIdSnapshot(Serializable id,
                                         EntityPersister persister)
                                  throws HibernateException

  Description copied from interface: `PersistenceContext`
  Get the values of the natural id fields as known to the underlying database, or null if the entity has no natural id or there is no corresponding row.

  Specified by:
    `getNaturalIdSnapshot` in interface `PersistenceContext`
  Parameters:
    `id` - The identifier of the entity for which to grab a snapshot
    `persister` - The persister of the entity.
  Returns:
    The current (non-cached) snapshot of the entity's natural id state.
  Throws:
    `HibernateException`

### getCachedDatabaseSnapshot

    public Object[] getCachedDatabaseSnapshot(EntityKey key)

  Retrieve the cached database snapshot for the requested entity key.

  This differs from `getDatabaseSnapshot(java.io.Serializable, org.hibernate.persister.entity.EntityPersister)` is two important respects:
  1. no snapshot is obtained from the database if not already cached
  2. an entry of `NO_ROW` here is interpretet as an exception

  Specified by:
    `getCachedDatabaseSnapshot` in interface `PersistenceContext`
  Parameters:
    `key` - The entity key for which to retrieve the cached snapshot
  Returns:
    The cached snapshot
  Throws:
    `IllegalStateException` - if the cached snapshot was == `NO_ROW`.

### addEntity

    public void addEntity(EntityKey key,
                          Object entity)

  Description copied from interface: `PersistenceContext`
  Add a canonical mapping from entity key to entity instance

  Specified by:
    `addEntity` in interface `PersistenceContext`
  Parameters:
    `key` - The key under which to add an entity
    `entity` - The entity instance to add

### getEntity

    public Object getEntity(EntityKey key)

  Get the entity instance associated with the given `EntityKey`

  Specified by:
    `getEntity` in interface `PersistenceContext`
  Parameters:
    `key` - The key under which to look for an entity
  Returns:
    The matching entity, or `null`

### containsEntity

    public boolean containsEntity(EntityKey key)

  Description copied from interface: `PersistenceContext`
  Is there an entity with the given key in the persistence context

  Specified by:
    `containsEntity` in interface `PersistenceContext`
  Parameters:
    `key` - The key under which to look for an entity
  Returns:
    `true` indicates an entity was found; otherwise `false`

### removeEntity

    public Object removeEntity(EntityKey key)

  Remove an entity from the session cache, also clear up other state associated with the entity, all except for the `EntityEntry`

  Specified by:
    `removeEntity` in interface `PersistenceContext`
  Parameters:
    `key` - The key whose matching entity should be removed
  Returns:
    The matching entity

### getEntity

    public Object getEntity(EntityUniqueKey euk)

  Get an entity cached by unique key

  Specified by:
    `getEntity` in interface `PersistenceContext`
  Parameters:
    `euk` - The unique (non-primary) key under which to look for an entity
  Returns:
    The located entity

### addEntity

    public void addEntity(EntityUniqueKey euk,
                          Object entity)

  Add an entity to the cache by unique key

  Specified by:
    `addEntity` in interface `PersistenceContext`
  Parameters:
    `euk` - The unique (non-primary) key under which to add an entity
    `entity` - The entity instance

### getEntry

    public EntityEntry getEntry(Object entity)

  Retrieve the EntityEntry representation of the given entity.

  Specified by:
    `getEntry` in interface `PersistenceContext`
  Parameters:
    `entity` - The entity for which to locate the EntityEntry.
  Returns:
    The EntityEntry for the given entity.

### removeEntry

    public EntityEntry removeEntry(Object entity)

  Remove an entity entry from the session cache

  Specified by:
    `removeEntry` in interface `PersistenceContext`
  Parameters:
    `entity` - The entity instance for which to remove the corresponding entry
  Returns:
    The matching entry

### isEntryFor

    public boolean isEntryFor(Object entity)

  Is there an EntityEntry for this instance?

  Specified by:
    `isEntryFor` in interface `PersistenceContext`
  Parameters:
    `entity` - The entity instance for which to check for an entry
  Returns:
    `true` indicates a matching entry was found.

### getCollectionEntry

    public CollectionEntry getCollectionEntry(PersistentCollection coll)

  Get the collection entry for a persistent collection

  Specified by:
    `getCollectionEntry` in interface `PersistenceContext`
  Parameters:
    `coll` - The persistent collection instance for which to locate the collection entry
  Returns:
    The matching collection entry

### addEntity

    public EntityEntry addEntity(Object entity,
                                 Status status,
                                 Object[] loadedState,
                                 EntityKey entityKey,
                                 Object version,
                                 LockMode lockMode,
                                 boolean existsInDatabase,
                                 EntityPersister persister,
                                 boolean disableVersionIncrement,
                                 boolean lazyPropertiesAreUnfetched)

  Adds an entity to the internal caches.

  Specified by:
    `addEntity` in interface `PersistenceContext`

### addEntry

    public EntityEntry addEntry(Object entity,
                                Status status,
                                Object[] loadedState,
                                Object rowId,
                                Serializable id,
                                Object version,
                                LockMode lockMode,
                                boolean existsInDatabase,
                                EntityPersister persister,
                                boolean disableVersionIncrement,
                                boolean lazyPropertiesAreUnfetched)

  Generates an appropriate EntityEntry instance and adds it to the event source's internal caches.

  Specified by:
    `addEntry` in interface `PersistenceContext`

### containsCollection

    public boolean containsCollection(PersistentCollection collection)

  Description copied from interface: `PersistenceContext`
  Is the given collection associated with this persistence context?

  Specified by:
    `containsCollection` in interface `PersistenceContext`

### containsProxy

    public boolean containsProxy(Object entity)

  Description copied from interface: `PersistenceContext`
  Is the given proxy associated with this persistence context?

  Specified by:
    `containsProxy` in interface `PersistenceContext`

### reassociateIfUninitializedProxy

    public boolean reassociateIfUninitializedProxy(Object value)
                                            throws MappingException

  Takes the given object and, if it represents a proxy, reassociates it with this event source.

  Specified by:
    `reassociateIfUninitializedProxy` in interface `PersistenceContext`
  Parameters:
    `value` - The possible proxy to be reassociated.
  Returns:
    Whether the passed value represented an actual proxy which got initialized.
  Throws:
    `MappingException`

### reassociateProxy

    public void reassociateProxy(Object value,
                                 Serializable id)
                          throws MappingException

  If a deleted entity instance is re-saved, and it has a proxy, we need to reset the identifier of the proxy

  Specified by:
    `reassociateProxy` in interface `PersistenceContext`
  Throws:
    `MappingException`

### unproxy

    public Object unproxy(Object maybeProxy)
                   throws HibernateException

  Get the entity instance underlying the given proxy, throwing an exception if the proxy is uninitialized. If the given object is not a proxy, simply return the argument.

  Specified by:
    `unproxy` in interface `PersistenceContext`
  Throws:
    `HibernateException`

### unproxyAndReassociate

    public Object unproxyAndReassociate(Object maybeProxy)
                                 throws HibernateException

  Possibly unproxy the given reference and reassociate it with the current session.

  Specified by:
    `unproxyAndReassociate` in interface `PersistenceContext`
  Parameters:
    `maybeProxy` - The reference to be unproxied if it currently represents a proxy.
  Returns:
    The unproxied instance.
  Throws:
    `HibernateException`

### checkUniqueness

    public void checkUniqueness(EntityKey key,
                                Object object)
                         throws HibernateException

  Attempts to check whether the given key represents an entity already loaded within the current session.

  Specified by:
    `checkUniqueness` in interface `PersistenceContext`
  Parameters:
    `object` - The entity reference against which to perform the uniqueness check.
  Throws:
    `HibernateException`

### narrowProxy

    public Object narrowProxy(Object proxy,
                              EntityPersister persister,
                              EntityKey key,
                              Object object)
                       throws HibernateException

  If the existing proxy is insufficiently "narrow" (derived), instantiate a new proxy and overwrite the registration of the old one. This breaks == and occurs only for "class" proxies rather than "interface" proxies. Also init the proxy to point to the given target implementation if necessary.

  Specified by:
    `narrowProxy` in interface `PersistenceContext`
  Parameters:
    `proxy` - The proxy instance to be narrowed.
    `persister` - The persister for the proxied entity.
    `key` - The internal cache key for the proxied entity.
    `object` - (optional) the actual proxied entity instance.
  Returns:
    An appropriately narrowed instance.
  Throws:
    `HibernateException`

### proxyFor

    public Object proxyFor(EntityPersister persister,
                           EntityKey key,
                           Object impl)
                    throws HibernateException

  Return the existing proxy associated with the given `EntityKey`, or the third argument (the entity associated with the key) if no proxy exists. Init the proxy to the target implementation, if necessary.

  Specified by:
    `proxyFor` in interface `PersistenceContext`
  Throws:
    `HibernateException`

### proxyFor

    public Object proxyFor(Object impl)
                    throws HibernateException

  Return the existing proxy associated with the given `EntityKey`, or the argument (the entity associated with the key) if no proxy exists. (slower than the form above)

  Specified by:
    `proxyFor` in interface `PersistenceContext`
  Throws:
    `HibernateException`

### getCollectionOwner

    public Object getCollectionOwner(Serializable key,
                                     CollectionPersister collectionPersister)
                              throws MappingException

  Get the entity that owns this persistent collection

  Specified by:
    `getCollectionOwner` in interface `PersistenceContext`
  Throws:
    `MappingException`

### getLoadedCollectionOwnerOrNull

    public Object getLoadedCollectionOwnerOrNull(PersistentCollection collection)

  Get the entity that owned this persistent collection when it was loaded

  Specified by:
    `getLoadedCollectionOwnerOrNull` in interface `PersistenceContext`
  Parameters:
    `collection` - The persistent collection
  Returns:
    the owner, if its entity ID is available from the collection's loaded key and the owner entity is in the persistence context; otherwise, returns null

### getLoadedCollectionOwnerIdOrNull

    public Serializable getLoadedCollectionOwnerIdOrNull(PersistentCollection collection)

  Get the ID for the entity that owned this persistent collection when it was loaded

  Specified by:
    `getLoadedCollectionOwnerIdOrNull` in interface `PersistenceContext`
  Parameters:
    `collection` - The persistent collection
  Returns:
    the owner ID if available from the collection's loaded key; otherwise, returns null

### addUninitializedCollection

    public void addUninitializedCollection(CollectionPersister persister,
                                           PersistentCollection collection,
                                           Serializable id)

  add a collection we just loaded up (still needs initializing)

  Specified by:
    `addUninitializedCollection` in interface `PersistenceContext`

### addUninitializedDetachedCollection

    public void addUninitializedDetachedCollection(CollectionPersister persister,
                                                   PersistentCollection collection)

  add a detached uninitialized collection

  Specified by:
    `addUninitializedDetachedCollection` in interface `PersistenceContext`

### addNewCollection

    public void addNewCollection(CollectionPersister persister,
                                 PersistentCollection collection)
                          throws HibernateException

  Add a new collection (ie. a newly created one, just instantiated by the application, with no database state or snapshot)

  Specified by:
    `addNewCollection` in interface `PersistenceContext`
  Parameters:
    `collection` - The collection to be associated with the persistence context
  Throws:
    `HibernateException`

### addInitializedDetachedCollection

    public void addInitializedDetachedCollection(CollectionPersister collectionPersister,
                                                 PersistentCollection collection)
                                          throws HibernateException

  add an (initialized) collection that was created by another session and passed into update() (ie. one with a snapshot and existing state on the database)

  Specified by:
    `addInitializedDetachedCollection` in interface `PersistenceContext`
  Throws:
    `HibernateException`

### addInitializedCollection

    public CollectionEntry addInitializedCollection(CollectionPersister persister,
                                                    PersistentCollection collection,
                                                    Serializable id)
                                             throws HibernateException

  add a collection we just pulled out of the cache (does not need initializing)

  Specified by:
    `addInitializedCollection` in interface `PersistenceContext`
  Throws:
    `HibernateException`

### getCollection

    public PersistentCollection getCollection(CollectionKey collectionKey)

  Get the collection instance associated with the `CollectionKey`

  Specified by:
    `getCollection` in interface `PersistenceContext`

### addNonLazyCollection

    public void addNonLazyCollection(PersistentCollection collection)

  Register a collection for non-lazy loading at the end of the two-phase load

  Specified by:
    `addNonLazyCollection` in interface `PersistenceContext`

### initializeNonLazyCollections

    public void initializeNonLazyCollections()
                                      throws HibernateException

  Force initialization of all non-lazy collections encountered during the current two-phase load (actually, this is a no-op, unless this is the "outermost" load)

  Specified by:
    `initializeNonLazyCollections` in interface `PersistenceContext`
  Throws:
    `HibernateException`

### getCollectionHolder

    public PersistentCollection getCollectionHolder(Object array)

  Get the `PersistentCollection` object for an array

  Specified by:
    `getCollectionHolder` in interface `PersistenceContext`

### addCollectionHolder

    public void addCollectionHolder(PersistentCollection holder)

  Register a `PersistentCollection` object for an array. Associates a holder with an array - MUST be called after loading array, since the array instance is not created until endLoad().

  Specified by:
    `addCollectionHolder` in interface `PersistenceContext`

### removeCollectionHolder

    public PersistentCollection removeCollectionHolder(Object array)

  Description copied from interface: `PersistenceContext`
  Remove the mapping of collection to holder during eviction of the owning entity

  Specified by:
    `removeCollectionHolder` in interface `PersistenceContext`

### getSnapshot

    public Serializable getSnapshot(PersistentCollection coll)

  Get the snapshot of the pre-flush collection state

  Specified by:
    `getSnapshot` in interface `PersistenceContext`

### getCollectionEntryOrNull

    public CollectionEntry getCollectionEntryOrNull(Object collection)

  Get the collection entry for a collection passed to filter, which might be a collection wrapper, an array, or an unwrapped collection. Return null if there is no entry.

  Specified by:
    `getCollectionEntryOrNull` in interface `PersistenceContext`

### getProxy

    public Object getProxy(EntityKey key)

  Get an existing proxy by key

  Specified by:
    `getProxy` in interface `PersistenceContext`

### addProxy

    public void addProxy(EntityKey key,
                         Object proxy)

  Add a proxy to the session cache

  Specified by:
    `addProxy` in interface `PersistenceContext`

### removeProxy

    public Object removeProxy(EntityKey key)

  Remove a proxy from the session cache.

  Additionally, ensure that any load optimization references such as batch or subselect loading get cleaned up as well.

  Specified by:
    `removeProxy` in interface `PersistenceContext`
  Parameters:
    `key` - The key of the entity proxy to be removed
  Returns:
    The proxy reference.

### getNullifiableEntityKeys

    public HashSet getNullifiableEntityKeys()

  Retrieve the set of EntityKeys representing nullifiable references

  Specified by:
    `getNullifiableEntityKeys` in interface `PersistenceContext`

### getEntitiesByKey

    public Map getEntitiesByKey()

  Description copied from interface: `PersistenceContext`
  Get the mapping from key value to entity instance

  Specified by:
    `getEntitiesByKey` in interface `PersistenceContext`

### getProxiesByKey

    public Map getProxiesByKey()

### getEntityEntries

    public Map getEntityEntries()

  Description copied from interface: `PersistenceContext`
  Get the mapping from entity instance to entity entry

  Specified by:
    `getEntityEntries` in interface `PersistenceContext`

### getCollectionEntries

    public Map getCollectionEntries()

  Description copied from interface: `PersistenceContext`
  Get the mapping from collection instance to collection entry

  Specified by:
    `getCollectionEntries` in interface `PersistenceContext`

### getCollectionsByKey

    public Map getCollectionsByKey()

  Description copied from interface: `PersistenceContext`
  Get the mapping from collection key to collection instance

  Specified by:
    `getCollectionsByKey` in interface `PersistenceContext`

### getCascadeLevel

    public int getCascadeLevel()

  Description copied from interface: `PersistenceContext`
  How deep are we cascaded?

  Specified by:
    `getCascadeLevel` in interface `PersistenceContext`

### incrementCascadeLevel

    public int incrementCascadeLevel()

  Description copied from interface: `PersistenceContext`
  Called before cascading

  Specified by:
    `incrementCascadeLevel` in interface `PersistenceContext`

### decrementCascadeLevel

    public int decrementCascadeLevel()

  Description copied from interface: `PersistenceContext`
  Called after cascading

  Specified by:
    `decrementCascadeLevel` in interface `PersistenceContext`

### isFlushing

    public boolean isFlushing()

  Description copied from interface: `PersistenceContext`
  Is a flush cycle currently in process?

  Specified by:
    `isFlushing` in interface `PersistenceContext`

### setFlushing

    public void setFlushing(boolean flushing)

  Description copied from interface: `PersistenceContext`
  Called before and after the flushcycle

  Specified by:
    `setFlushing` in interface `PersistenceContext`

### beforeLoad

    public void beforeLoad()

  Call this before beginning a two-phase load

  Specified by:
    `beforeLoad` in interface `PersistenceContext`

### afterLoad

    public void afterLoad()

  Call this after finishing a two-phase load

  Specified by:
    `afterLoad` in interface `PersistenceContext`

### isLoadFinished

    public boolean isLoadFinished()

  Description copied from interface: `PersistenceContext`
  Is in a two-phase load?

  Specified by:
    `isLoadFinished` in interface `PersistenceContext`

### toString

    public String toString()

  Returns a string representation of the object.

  Specified by:
    `toString` in interface `PersistenceContext`
  Overrides:
    `toString` in class `Object`
  Returns:
    a string representation of the object.

### getOwnerId

    public Serializable getOwnerId(String entityName,
                                   String propertyName,
                                   Object childEntity,
                                   Map mergeMap)

  Search `this` persistence context for an associated entity instance which is considered the "owner" of the given `childEntity`, and return that owner's id value. This is performed in the scenario of a uni-directional, non-inverse one-to-many collection (which means that the collection elements do not maintain a direct reference to the owner).

  As such, the processing here is basically to loop over every entity currently associated with this persistence context and for those of the correct entity (sub) type to extract its collection role property value and see if the child is contained within that collection. If so, we have found the owner; if not, we go on.

  Also need to account for `mergeMap` which acts as a local copy cache managed for the duration of a merge operation. It represents a map of the detached entity instances pointing to the corresponding managed instance.

  Specified by:
    `getOwnerId` in interface `PersistenceContext`
  Parameters:
    `entityName` - The entity name for the entity type which would own the child
    `propertyName` - The name of the property on the owning entity type which would name this child association.
    `childEntity` - The child entity instance for which to locate the owner instance id.
    `mergeMap` - A map of non-persistent instances from an on-going merge operation (possibly null).
  Returns:
    The id of the entityName instance which is said to own the child; null if an appropriate owner not located.

### getIndexInOwner

    public Object getIndexInOwner(String entity,
                                  String property,
                                  Object childEntity,
                                  Map mergeMap)

  Search the persistence context for an index of the child object, given a collection role

  Specified by:
    `getIndexInOwner` in interface `PersistenceContext`

### addNullProperty

    public void addNullProperty(EntityKey ownerKey,
                                String propertyName)

  Record the fact that the association belonging to the keyed entity is null.

  Specified by:
    `addNullProperty` in interface `PersistenceContext`

### isPropertyNull

    public boolean isPropertyNull(EntityKey ownerKey,
                                  String propertyName)

  Is the association property belonging to the keyed entity null?

  Specified by:
    `isPropertyNull` in interface `PersistenceContext`

### isReadOnly

    public boolean isReadOnly(Object entityOrProxy)

  Description copied from interface: `PersistenceContext`
  Is the entity or proxy read-only?

  To determine the default read-only/modifiable setting used for entities and proxies that are loaded into the session use `Session.isDefaultReadOnly()`

  Specified by:
    `isReadOnly` in interface `PersistenceContext`
  Parameters:
    `entityOrProxy` - an entity or proxy
  Returns:
    `true` if the object is read-only; otherwise `false` to indicate that the object is modifiable.

### setReadOnly

    public void setReadOnly(Object object,
                            boolean readOnly)

  Description copied from interface: `PersistenceContext`
  Set an unmodified persistent object to read-only mode, or a read-only object to modifiable mode. Read-only entities are not dirty-checked and snapshots of persistent state are not maintained. Read-only entities can be modified, but changes are not persisted. When a proxy is initialized, the loaded entity will have the same read-only/modifiable setting as the uninitialized proxy has, regardless of the session's current setting. If the entity or proxy already has the specified read-only/modifiable setting, then this method does nothing.

  Specified by:
    `setReadOnly` in interface `PersistenceContext`
  Parameters:
    `object` - an entity or proxy
    `readOnly` - if `true`, the entity or proxy is made read-only; otherwise, the entity or proxy is made modifiable.
  See Also:
    `Session.setDefaultReadOnly(boolean)`, `Session.setReadOnly(java.lang.Object, boolean)`, `Query.setReadOnly(boolean)`

### replaceDelayedEntityIdentityInsertKeys

    public void replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey,
                                                       Serializable generatedId)

  Specified by:
    `replaceDelayedEntityIdentityInsertKeys` in interface `PersistenceContext`

### serialize

    public void serialize(ObjectOutputStream oos)
                   throws IOException

  Used by the owning session to explicitly control serialization of the persistence context.

  Parameters:
    `oos` - The stream to which the persistence context should get written
  Throws:
    `IOException` - serialization errors.

### deserialize

    public static StatefulPersistenceContext deserialize(ObjectInputStream ois,
                                                         SessionImplementor session)
                                                  throws IOException,
                                                         ClassNotFoundException

  Throws:
    `IOException`
    `ClassNotFoundException`

### addChildParent

    public void addChildParent(Object child,
                               Object parent)

  Description copied from interface: `PersistenceContext`
  Add a child/parent relation to cache for cascading op

  Specified by:
    `addChildParent` in interface `PersistenceContext`
  Parameters:
    `child` - The child of the relationship
    `parent` - The parent of the relationship

### removeChildParent

    public void removeChildParent(Object child)

  Description copied from interface: `PersistenceContext`
  Remove child/parent relation from cache

  Specified by:
    `removeChildParent` in interface `PersistenceContext`
  Parameters:
    `child` - The child to be removed.

### registerInsertedKey

    public void registerInsertedKey(EntityPersister persister,
                                    Serializable id)

  Description copied from interface: `PersistenceContext`
  Register keys inserted during the current transaction

  Specified by:
    `registerInsertedKey` in interface `PersistenceContext`
  Parameters:
    `persister` - The entity persister
    `id` - The id

### wasInsertedDuringTransaction

    public boolean wasInsertedDuringTransaction(EntityPersister persister,
                                                Serializable id)

  Description copied from interface: `PersistenceContext`
  Allows callers to check to see if the identified entity was inserted during the current transaction.

  Specified by:
    `wasInsertedDuringTransaction` in interface `PersistenceContext`
  Parameters:
    `persister` - The entity persister
    `id` - The id
  Returns:
    True if inserted during this transaction, false otherwise.

### getNaturalIdHelper

    public PersistenceContext.NaturalIdHelper getNaturalIdHelper()

  Description copied from interface: `PersistenceContext`
  Access to the natural-id helper for this persistence context

  Specified by:
    `getNaturalIdHelper` in interface `PersistenceContext`
  Returns:
    This persistence context's natural-id helper

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2012 Red Hat, Inc. All Rights Reserved.