java.lang.Object | |
↳ | org.hibernate.engine.StatefulPersistenceContext |
A PersistenceContext represents the state of persistent "stuff" which Hibernate is tracking. This includes persistent entities, collections, as well as proxies generated.
There is meant to be a one-to-one correspondence between a SessionImpl and a PersistentContext. The SessionImpl uses the PersistentContext to track the current state of its context. Event-listeners then use the PersistentContext to drive their processing.Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
NO_ROW |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a PersistentContext, bound to the given session.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Put child/parent relation to cache for cascading op
| |||||||||||
Register a PersistentCollection object for an array.
| |||||||||||
Add a canonical mapping from entity key to entity instance
| |||||||||||
Adds an entity to the internal caches.
| |||||||||||
Add an entity to the cache by unique key
| |||||||||||
Generates an appropriate EntityEntry instance and adds it
to the event source's internal caches.
| |||||||||||
add a collection we just pulled out of the cache (does not need initializing)
| |||||||||||
add an (initialized) collection that was created by another session and passed
into update() (ie.
| |||||||||||
Add a new collection (ie.
| |||||||||||
Register a collection for non-lazy loading at the end of the
two-phase load
| |||||||||||
Record the fact that the association belonging to the keyed
entity is null.
| |||||||||||
Add a proxy to the session cache
| |||||||||||
add a collection we just loaded up (still needs initializing)
| |||||||||||
add a detached uninitialized collection
| |||||||||||
Add a collection which has no owner loaded
| |||||||||||
Call this after finishing a two-phase load
| |||||||||||
Called after transactions end
| |||||||||||
Call this before begining a two-phase load
| |||||||||||
Attempts to check whether the given key represents an entity already loaded within the
current session.
| |||||||||||
Clear the state of the persistence context
| |||||||||||
Is the given collection associated with this persistence context?
| |||||||||||
Is there an entity with the given key in the persistence context
| |||||||||||
Is the given proxy associated with this persistence context?
| |||||||||||
Called after cascading
| |||||||||||
Get the BatchFetchQueue, instantiating one if
necessary.
| |||||||||||
Retrieve the cached database snapshot for the requested entity key.
| |||||||||||
Do we already know that the entity does not exist in the
database?
| |||||||||||
Get the collection instance associated with the CollectionKey
| |||||||||||
Get the mapping from collection instance to collection entry
| |||||||||||
Get the collection entry for a persistent collection
| |||||||||||
Get the collection entry for a collection passed to filter,
which might be a collection wrapper, an array, or an unwrapped
collection.
| |||||||||||
Get the PersistentCollection object for an array
| |||||||||||
Get the entity that owns this persistent collection
| |||||||||||
Get the mapping from collection key to collection instance
| |||||||||||
Get the current state of the entity as known to the underlying
database, or null if there is no corresponding row
| |||||||||||
Get the mapping from key value to entity instance
| |||||||||||
Get an entity cached by unique key
| |||||||||||
Get the entity instance associated with the given
EntityKey
| |||||||||||
Get the mapping from entity instance to entity entry
| |||||||||||
Retreive the EntityEntry representation of the given entity.
| |||||||||||
Search the persistence context for an index of the child object,
given a collection role
| |||||||||||
Retrieve this persistence context's managed load context.
| |||||||||||
Get the ID for the entity that owned this persistent collection when it was loaded
| |||||||||||
Get the entity that owned this persistent collection when it was loaded
| |||||||||||
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.
| |||||||||||
Retrieve the set of EntityKeys representing nullifiable references
| |||||||||||
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.
| |||||||||||
Get an existing proxy by key
| |||||||||||
Get the session to which this persistence context is bound.
| |||||||||||
Get the snapshot of the pre-flush collection state
| |||||||||||
Called before cascading
| |||||||||||
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)
| |||||||||||
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:
| |||||||||||
Is there an EntityEntry for this instance?
| |||||||||||
Is a flush cycle currently in process?
| |||||||||||
Is in a two-phase load?
| |||||||||||
Is the association property belonging to the keyed entity null?
| |||||||||||
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:
| |||||||||||
If the existing proxy is insufficiently "narrow" (derived), instantiate a new proxy
and overwrite the registration of the old one.
| |||||||||||
Return the existing proxy associated with the given EntityKey, or the
argument (the entity associated with the key) if no proxy exists.
| |||||||||||
Return the existing proxy associated with the given EntityKey, or the
third argument (the entity associated with the key) if no proxy exists.
| |||||||||||
Takes the given object and, if it represents a proxy, reassociates it with this event source.
| |||||||||||
If a deleted entity instance is re-saved, and it has a proxy, we need to
reset the identifier of the proxy
| |||||||||||
Register keys inserted during the current transaction
| |||||||||||
Remove child/parent relation from cache
| |||||||||||
Remove the mapping of collection to holder during eviction
of the owning entity
| |||||||||||
Remove an entity from the session cache, also clear
up other state associated with the entity, all except
for the EntityEntry
| |||||||||||
Remove an entity entry from the session cache
| |||||||||||
Remove a proxy from the session cache.
| |||||||||||
Used by the owning session to explicitly control serialization of the
persistence context.
| |||||||||||
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.
| |||||||||||
Set the status of an entry
| |||||||||||
Called before and after the flushcycle
| |||||||||||
Set an unmodified persistent object to read-only mode, or a read-only
object to modifiable mode.
| |||||||||||
Returns a string representation of the object.
| |||||||||||
Get the entity instance underlying the given proxy, throwing
an exception if the proxy is uninitialized.
| |||||||||||
Possibly unproxy the given reference and reassociate it with the current session.
| |||||||||||
Get and remove a collection whose owner is not yet loaded,
when its owner is being loaded
| |||||||||||
Allows callers to check to see if the identified entity was inserted during the current transaction.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
org.hibernate.engine.PersistenceContext
|
Constructs a PersistentContext, bound to the given session.
session | The session "owning" this context. |
---|
Put child/parent relation to cache for cascading op
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().
Add a canonical mapping from entity key to entity instance
Adds an entity to the internal caches.
Generates an appropriate EntityEntry instance and adds it to the event source's internal caches.
add a collection we just pulled out of the cache (does not need initializing)
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)
HibernateException |
---|
Add a new collection (ie. a newly created one, just instantiated by the application, with no database state or snapshot)
collection | The collection to be associated with the persistence context |
---|
HibernateException |
---|
Register a collection for non-lazy loading at the end of the two-phase load
Record the fact that the association belonging to the keyed entity is null.
add a collection we just loaded up (still needs initializing)
add a detached uninitialized collection
Add a collection which has no owner loaded
Call this after finishing a two-phase load
Called after transactions end
Call this before begining a two-phase load
Attempts to check whether the given key represents an entity already loaded within the current session.
object | The entity reference against which to perform the uniqueness check. |
---|
HibernateException |
---|
Clear the state of the persistence context
Is the given collection associated with this persistence context?
Is there an entity with the given key in the persistence context
Is the given proxy associated with this persistence context?
Called after cascading
Get the BatchFetchQueue, instantiating one if necessary.
Retrieve the cached database snapshot for the requested entity key.
This differs fromgetDatabaseSnapshot(Serializable, EntityPersister)
is two important respects:NO_ROW
here is interpretet as an exceptionkey | The entity key for which to retrieve the cached snapshot |
---|
IllegalStateException | if the cached snapshot was == NO_ROW .
|
---|
Do we already know that the entity does not exist in the database?
Get the collection instance associated with the CollectionKey
Get the collection entry for a persistent 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.
Get the PersistentCollection object for an array
Get the entity that owns this persistent collection
MappingException |
---|
Get the current state of the entity as known to the underlying database, or null if there is no corresponding row
HibernateException |
---|
Retreive the EntityEntry representation of the given entity.
entity | The entity for which to locate the EntityEntry. |
---|
Search the persistence context for an index of the child object, given a collection role
Retrieve this persistence context's managed load context.
Get the ID for the entity that owned this persistent collection when it was loaded
collection | The persistent collection |
---|
Get the entity that owned this persistent collection when it was loaded
collection | The persistent collection |
---|
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.
HibernateException |
---|
Retrieve the set of EntityKeys representing nullifiable references
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.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). |
Get the session to which this persistence context is bound.
Get the snapshot of the pre-flush collection state
Called before cascading
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)
HibernateException |
---|
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:
Is a flush cycle currently in process?
Is in a two-phase load?
Is the association property belonging to the keyed entity null?
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:
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.
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. |
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)
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.
HibernateException |
---|
Takes the given object and, if it represents a proxy, reassociates it with this event source.
value | The possible proxy to be reassociated. |
---|
MappingException |
---|
If a deleted entity instance is re-saved, and it has a proxy, we need to reset the identifier of the proxy
MappingException |
---|
Register keys inserted during the current transaction
persister | The entity persister |
---|---|
id | The id |
Remove the mapping of collection to holder during eviction of the owning entity
Remove an entity from the session cache, also clear up other state associated with the entity, all except for the EntityEntry
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.key | The key of the entity proxy to be removed |
---|
Used by the owning session to explicitly control serialization of the persistence context.
oos | The stream to which the persistence context should get written |
---|
IOException | serialization errors. |
---|
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)
defaultReadOnly | true, the default for loaded entities/proxies is read-only; false, the default for loaded entities/proxies is modifiable |
---|
Called before and after the flushcycle
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:
readOnly | if true, the entity or proxy is made read-only; if false, the entity or proxy is made modifiable. |
---|
Returns a string representation of the object.
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.
HibernateException |
---|
Possibly unproxy the given reference and reassociate it with the current session.
maybeProxy | The reference to be unproxied if it currently represents a proxy. |
---|
HibernateException |
---|
Get and remove a collection whose owner is not yet loaded, when its owner is being loaded
Allows callers to check to see if the identified entity was inserted during the current transaction.
persister | The entity persister |
---|---|
id | The id |