public interface

PersistenceContext

org.hibernate.engine.PersistenceContext
Known Indirect Subclasses

Class Overview

Holds the state of the persistence context, including the first-level cache, entries, snapshots, proxies, etc.

Summary

Public Methods
abstract void addChildParent(Object parent, Object child)
Put child/parent relation to cache for cascading op
abstract void addCollectionHolder(PersistentCollection holder)
Register a PersistentCollection object for an array.
abstract void addEntity(EntityKey key, Object entity)
Add a canonical mapping from entity key to entity instance
abstract 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.
abstract void addEntity(EntityUniqueKey euk, Object entity)
Add an entity to the cache by unique key
abstract 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.
abstract CollectionEntry addInitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id)
add a collection we just pulled out of the cache (does not need initializing)
abstract void addInitializedDetachedCollection(CollectionPersister collectionPersister, PersistentCollection collection)
add an (initialized) collection that was created by another session and passed into update() (ie.
abstract void addNewCollection(CollectionPersister persister, PersistentCollection collection)
Add a new collection (ie.
abstract void addNonLazyCollection(PersistentCollection collection)
Register a collection for non-lazy loading at the end of the two-phase load
abstract void addNullProperty(EntityKey ownerKey, String propertyName)
Record the fact that the association belonging to the keyed entity is null.
abstract void addProxy(EntityKey key, Object proxy)
Add a proxy to the session cache
abstract void addUninitializedCollection(CollectionPersister persister, PersistentCollection collection, Serializable id)
add a collection we just loaded up (still needs initializing)
abstract void addUninitializedDetachedCollection(CollectionPersister persister, PersistentCollection collection)
add a detached uninitialized collection
abstract void addUnownedCollection(CollectionKey key, PersistentCollection collection)
Add a collection which has no owner loaded
abstract void afterLoad()
Call this after finishing a two-phase load
abstract void afterTransactionCompletion()
Called after transactions end
abstract void beforeLoad()
Call this before beginning a two-phase load
abstract void checkUniqueness(EntityKey key, Object object)
Attempts to check whether the given key represents an entity already loaded within the current session.
abstract void clear()
Clear the state of the persistence context
abstract boolean containsCollection(PersistentCollection collection)
Is the given collection associated with this persistence context?
abstract boolean containsEntity(EntityKey key)
Is there an entity with the given key in the persistence context
abstract boolean containsProxy(Object proxy)
Is the given proxy associated with this persistence context?
abstract int decrementCascadeLevel()
Called after cascading
abstract BatchFetchQueue getBatchFetchQueue()
Get the BatchFetchQueue, instantiating one if necessary.
abstract Object[] getCachedDatabaseSnapshot(EntityKey key)
abstract int getCascadeLevel()
How deep are we cascaded?
abstract PersistentCollection getCollection(CollectionKey collectionKey)
Get the collection instance associated with the CollectionKey
abstract Map getCollectionEntries()
Get the mapping from collection instance to collection entry
abstract CollectionEntry getCollectionEntry(PersistentCollection coll)
Get the collection entry for a persistent collection
abstract 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.
abstract PersistentCollection getCollectionHolder(Object array)
Get the PersistentCollection object for an array
abstract Object getCollectionOwner(Serializable key, CollectionPersister collectionPersister)
Get the entity that owns this persistent collection
abstract Map getCollectionsByKey()
Get the mapping from collection key to collection instance
abstract 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
abstract Map getEntitiesByKey()
Get the mapping from key value to entity instance
abstract Object getEntity(EntityUniqueKey euk)
Get an entity cached by unique key
abstract Object getEntity(EntityKey key)
Get the entity instance associated with the given EntityKey
abstract Map getEntityEntries()
Get the mapping from entity instance to entity entry
abstract EntityEntry getEntry(Object entity)
Retrieve the EntityEntry representation of the given entity.
abstract Object getIndexInOwner(String entity, String property, Object childObject, Map mergeMap)
Search the persistence context for an index of the child object, given a collection role
abstract LoadContexts getLoadContexts()
Retrieve this persistence context's managed load context.
abstract Serializable getLoadedCollectionOwnerIdOrNull(PersistentCollection collection)
Get the ID for the entity that owned this persistent collection when it was loaded
abstract Object getLoadedCollectionOwnerOrNull(PersistentCollection collection)
Get the entity that owned this persistent collection when it was loaded
abstract 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.
abstract HashSet getNullifiableEntityKeys()
Retrieve the set of EntityKeys representing nullifiable references
abstract Serializable getOwnerId(String entity, String property, Object childObject, Map mergeMap)
Search the persistence context for an owner for the child object, given a collection role
abstract Object getProxy(EntityKey key)
Get an existing proxy by key
abstract SessionImplementor getSession()
Get the session to which this persistence context is bound.
abstract Serializable getSnapshot(PersistentCollection coll)
Get the snapshot of the pre-flush collection state
abstract boolean hasNonReadOnlyEntities()
abstract int incrementCascadeLevel()
Called before cascading
abstract 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)
abstract 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:
abstract boolean isEntryFor(Object entity)
Is there an EntityEntry for this instance?
abstract boolean isFlushing()
Is a flush cycle currently in process?
abstract boolean isLoadFinished()
Is in a two-phase load?
abstract boolean isPropertyNull(EntityKey ownerKey, String propertyName)
Is the association property belonging to the keyed entity null?
abstract boolean isReadOnly(Object entityOrProxy)
Is the entity or proxy read-only? To get the default read-only/modifiable setting used for entities and proxies that are loaded into the session:
abstract boolean isStateless()
abstract 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.
abstract 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.
abstract 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.
abstract boolean reassociateIfUninitializedProxy(Object value)
Takes the given object and, if it represents a proxy, reassociates it with this event source.
abstract 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
abstract void registerInsertedKey(EntityPersister persister, Serializable id)
Register keys inserted during the current transaction
abstract void removeChildParent(Object child)
Remove child/parent relation from cache
abstract PersistentCollection removeCollectionHolder(Object array)
Remove the mapping of collection to holder during eviction of the owning entity
abstract 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
abstract EntityEntry removeEntry(Object entity)
Remove an entity entry from the session cache
abstract Object removeProxy(EntityKey key)
Remove a proxy from the session cache
abstract void replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey, Serializable generatedId)
abstract void setDefaultReadOnly(boolean readOnly)
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.
abstract void setEntryStatus(EntityEntry entry, Status status)
Set the status of an entry
abstract void setFlushing(boolean flushing)
Called before and after the flushcycle
abstract void setReadOnly(Object entityOrProxy, boolean readOnly)
Set an unmodified persistent object to read-only mode, or a read-only object to modifiable mode.
abstract String toString()
Returns a string representation of the object.
abstract Object unproxy(Object maybeProxy)
Get the entity instance underlying the given proxy, throwing an exception if the proxy is uninitialized.
abstract Object unproxyAndReassociate(Object maybeProxy)
Possibly unproxy the given reference and reassociate it with the current session.
abstract PersistentCollection useUnownedCollection(CollectionKey key)
Get and remove a collection whose owner is not yet loaded, when its owner is being loaded
abstract boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id)
Allows callers to check to see if the identified entity was inserted during the current transaction.

Public Methods

public abstract void addChildParent (Object parent, Object child)

Put child/parent relation to cache for cascading op

public abstract 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().

public abstract void addEntity (EntityKey key, Object entity)

Add a canonical mapping from entity key to entity instance

public abstract 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.

public abstract void addEntity (EntityUniqueKey euk, Object entity)

Add an entity to the cache by unique key

public abstract 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.

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

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

public abstract void addInitializedDetachedCollection (CollectionPersister collectionPersister, PersistentCollection collection)

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)

public abstract void addNewCollection (CollectionPersister persister, PersistentCollection collection)

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

Parameters
collection The collection to be associated with the persistence context

public abstract void addNonLazyCollection (PersistentCollection collection)

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

public abstract void addNullProperty (EntityKey ownerKey, String propertyName)

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

public abstract void addProxy (EntityKey key, Object proxy)

Add a proxy to the session cache

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

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

public abstract void addUninitializedDetachedCollection (CollectionPersister persister, PersistentCollection collection)

add a detached uninitialized collection

public abstract void addUnownedCollection (CollectionKey key, PersistentCollection collection)

Add a collection which has no owner loaded

public abstract void afterLoad ()

Call this after finishing a two-phase load

public abstract void afterTransactionCompletion ()

Called after transactions end

public abstract void beforeLoad ()

Call this before beginning a two-phase load

public abstract void checkUniqueness (EntityKey key, Object object)

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

Parameters
object The entity reference against which to perform the uniqueness check.

public abstract void clear ()

Clear the state of the persistence context

public abstract boolean containsCollection (PersistentCollection collection)

Is the given collection associated with this persistence context?

public abstract boolean containsEntity (EntityKey key)

Is there an entity with the given key in the persistence context

public abstract boolean containsProxy (Object proxy)

Is the given proxy associated with this persistence context?

public abstract int decrementCascadeLevel ()

Called after cascading

public abstract BatchFetchQueue getBatchFetchQueue ()

Get the BatchFetchQueue, instantiating one if necessary.

public abstract Object[] getCachedDatabaseSnapshot (EntityKey key)

public abstract int getCascadeLevel ()

How deep are we cascaded?

public abstract PersistentCollection getCollection (CollectionKey collectionKey)

Get the collection instance associated with the CollectionKey

public abstract Map getCollectionEntries ()

Get the mapping from collection instance to collection entry

public abstract CollectionEntry getCollectionEntry (PersistentCollection coll)

Get the collection entry for a persistent collection

public abstract 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.

public abstract PersistentCollection getCollectionHolder (Object array)

Get the PersistentCollection object for an array

public abstract Object getCollectionOwner (Serializable key, CollectionPersister collectionPersister)

Get the entity that owns this persistent collection

public abstract Map getCollectionsByKey ()

Get the mapping from collection key to collection instance

public abstract 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

public abstract Map getEntitiesByKey ()

Get the mapping from key value to entity instance

public abstract Object getEntity (EntityUniqueKey euk)

Get an entity cached by unique key

public abstract Object getEntity (EntityKey key)

Get the entity instance associated with the given EntityKey

public abstract Map getEntityEntries ()

Get the mapping from entity instance to entity entry

public abstract EntityEntry getEntry (Object entity)

Retrieve the EntityEntry representation of the given entity.

Parameters
entity The entity for which to locate the EntityEntry.
Returns
  • The EntityEntry for the given entity.

public abstract Object getIndexInOwner (String entity, String property, Object childObject, Map mergeMap)

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

public abstract LoadContexts getLoadContexts ()

Retrieve this persistence context's managed load context.

Returns
  • The load context

public abstract Serializable getLoadedCollectionOwnerIdOrNull (PersistentCollection collection)

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

Parameters
collection The persistent collection
Returns
  • the owner ID if available from the collection's loaded key; otherwise, returns null

public abstract Object getLoadedCollectionOwnerOrNull (PersistentCollection collection)

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

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

public abstract 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.

public abstract HashSet getNullifiableEntityKeys ()

Retrieve the set of EntityKeys representing nullifiable references

public abstract Serializable getOwnerId (String entity, String property, Object childObject, Map mergeMap)

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

public abstract Object getProxy (EntityKey key)

Get an existing proxy by key

public abstract SessionImplementor getSession ()

Get the session to which this persistence context is bound.

Returns
  • The session.

public abstract Serializable getSnapshot (PersistentCollection coll)

Get the snapshot of the pre-flush collection state

public abstract boolean hasNonReadOnlyEntities ()

Returns
  • false if we know for certain that all the entities are read-only

public abstract int incrementCascadeLevel ()

Called before cascading

public abstract 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)

public abstract 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:

Returns
  • true, loaded entities/proxies will be made read-only by default; false, loaded entities/proxies will be made modifiable by default.

public abstract boolean isEntryFor (Object entity)

Is there an EntityEntry for this instance?

public abstract boolean isFlushing ()

Is a flush cycle currently in process?

public abstract boolean isLoadFinished ()

Is in a two-phase load?

public abstract boolean isPropertyNull (EntityKey ownerKey, String propertyName)

Is the association property belonging to the keyed entity null?

public abstract boolean isReadOnly (Object entityOrProxy)

Is the entity or proxy read-only? To get the default read-only/modifiable setting used for entities and proxies that are loaded into the session:

Returns
  • true, the object is read-only; false, the object is modifiable.

public abstract boolean isStateless ()

public abstract 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. 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.

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.

public abstract 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. (slower than the form above)

public abstract 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. Init the proxy to the target implementation, if necessary.

public abstract boolean reassociateIfUninitializedProxy (Object value)

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

Parameters
value The possible proxy to be reassociated.
Returns
  • Whether the passed value represented an actual proxy which got initialized.

public abstract 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

public abstract void registerInsertedKey (EntityPersister persister, Serializable id)

Register keys inserted during the current transaction

Parameters
persister The entity persister
id The id

public abstract void removeChildParent (Object child)

Remove child/parent relation from cache

public abstract PersistentCollection removeCollectionHolder (Object array)

Remove the mapping of collection to holder during eviction of the owning entity

public abstract 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

public abstract EntityEntry removeEntry (Object entity)

Remove an entity entry from the session cache

public abstract Object removeProxy (EntityKey key)

Remove a proxy from the session cache

public abstract void replaceDelayedEntityIdentityInsertKeys (EntityKey oldKey, Serializable generatedId)

public abstract void setDefaultReadOnly (boolean readOnly)

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)

Parameters
readOnly true, the default for loaded entities/proxies is read-only; false, the default for loaded entities/proxies is modifiable

public abstract void setEntryStatus (EntityEntry entry, Status status)

Set the status of an entry

public abstract void setFlushing (boolean flushing)

Called before and after the flushcycle

public abstract void setReadOnly (Object entityOrProxy, boolean readOnly)

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. To set the default read-only/modifiable setting used for entities and proxies that are loaded into this persistence context:

Parameters
readOnly if true, the entity or proxy is made read-only; if false, the entity or proxy is made modifiable.

public abstract String toString ()

Returns a string representation of the object.

Returns
  • a string representation of the object.

public abstract Object unproxy (Object maybeProxy)

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.

public abstract Object unproxyAndReassociate (Object maybeProxy)

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

Parameters
maybeProxy The reference to be unproxied if it currently represents a proxy.
Returns
  • The unproxied instance.

public abstract PersistentCollection useUnownedCollection (CollectionKey key)

Get and remove a collection whose owner is not yet loaded, when its owner is being loaded

public abstract boolean wasInsertedDuringTransaction (EntityPersister persister, Serializable id)

Allows callers to check to see if the identified entity was inserted during the current transaction.

Parameters
persister The entity persister
id The id
Returns
  • True if inserted during this transaction, false otherwise.