Class StatefulPersistenceContext
- All Implemented Interfaces:
PersistenceContext
PersistenceContext contract, meaning that we maintain this
state throughout the life of the persistence context.- Author:
- Steve Ebersole, Sanne Grinovero
-
Field Summary
Fields inherited from interface org.hibernate.engine.spi.PersistenceContext
NO_ROW -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a PersistentContext, bound to the given session. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChildParent(Object child, Object parent) Add a child/parent relation to cache for cascading opaddCollectionByKey(CollectionKey collectionKey, PersistentCollection<?> persistentCollection) Adds a collection in the collections-by-key map.voidaddCollectionHolder(PersistentCollection<?> holder) Register aPersistentCollectionobject for an array.voidaddEnhancedProxy(EntityKey key, PersistentAttributeInterceptable entity) Cross betweenPersistenceContext.addEntity(EntityKey, Object)andPersistenceContext.addProxy(EntityKey, Object)for use with enhancement-as-proxyaddEntity(Object entity, Status status, Object[] loadedState, EntityKey entityKey, Object version, LockMode lockMode, boolean existsInDatabase, EntityPersister persister, boolean disableVersionIncrement) Adds an entity to the internal caches.voidAdd a canonical mapping from entity key to entity instancevoidaddEntity(EntityUniqueKey euk, Object entity) Add an entity to the cache by unique keyaddEntityHolder(EntityKey key, Object entity) addEntry(Object entity, Status status, Object[] loadedState, Object rowId, Object id, Object version, LockMode lockMode, boolean existsInDatabase, EntityPersister persister, boolean disableVersionIncrement) Generates an appropriate EntityEntry instance and adds it to the event source's internal caches.addInitializedCollection(CollectionPersister persister, PersistentCollection<?> collection, Object id) add a collection we just pulled out of the cache (does not need initializing)voidaddInitializedDetachedCollection(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)voidaddNewCollection(CollectionPersister persister, PersistentCollection<?> collection) Add a new collection (ie. a newly created one, just instantiated by the application, with no database state or snapshot)voidaddNonLazyCollection(PersistentCollection<?> collection) Register a collection for non-lazy loading at the end of the two-phase loadvoidaddNullProperty(EntityKey ownerKey, String propertyName) Record the fact that the association belonging to the keyed entity is null.voidAdd a proxy to the session cacheaddReferenceEntry(Object entity, Status status) voidaddUninitializedCollection(CollectionPersister persister, PersistentCollection<?> collection, Object id) add a collection we just loaded up (still needs initializing)voidaddUninitializedDetachedCollection(CollectionPersister persister, PersistentCollection<?> collection) add a detached uninitialized collectionvoidCall this after finishing a two-phase loadvoidCalled after transactions endvoidCall this before beginning a two-phase loadvoidvoidcheckUniqueness(EntityKey key, Object object) Attempts to check whether the given key represents an entity already loaded within the current session.claimEntityHolderIfPossible(EntityKey key, Object entity, JdbcValuesSourceProcessingState processingState, EntityInitializer<?> initializer) Return an existing entity holder for the entity key, possibly creating one if necessary.voidclear()Clear the state of the persistence contextvoidRemove all state of the collections-by-key map.booleancontainsCollection(PersistentCollection<?> collection) Is the given collection associated with this persistence context?booleanbooleanbooleancontainsEntity(EntityKey key) Is there an entity with the given key in the persistence contextbooleanbooleanChecks if a certainEntityKeywas registered as nullifiable on thisPersistenceContext.booleancontainsProxy(Object entity) Is the given proxy associated with this persistence context?intCalled after cascadingstatic StatefulPersistenceContextdeserialize(ObjectInputStream ois, SessionImplementor session) Used by the owning session to explicitly control deserialization of the persistence context.detachEntity(EntityKey key) Remove theEntityHolderand set its state to DETACHEDvoidvoidforEachCollectionEntry(BiConsumer<PersistentCollection<?>, CollectionEntry> action, boolean concurrent) Execute some action on each entry of the collectionEntries map, optionally iterating on a defensive copy.Get theBatchFetchQueue, instantiating one if necessary.Object[]Retrieve the cached database snapshot for the requested entity key.intHow deep are we cascaded?getCollection(CollectionKey collectionKey) Get the collection instance associated with theCollectionKey@Nullable Map<PersistentCollection<?>,CollectionEntry> Deprecated.We should not expose this directly: the other accessors that have been created as a replacement have better chances of skipping initializing this map, which is a good performance improvement.intThe size of the internal map storing all collection entries.getCollectionEntry(PersistentCollection<?> coll) Get the collection entry for a persistent collectiongetCollectionHolder(Object array) Get thePersistentCollectionobject for an arraygetCollectionOwner(Object key, CollectionPersister collectionPersister) Get the entity that owns this persistent collectionGet the mapping from collection key to collection instanceObject[]getDatabaseSnapshot(Object id, EntityPersister persister) Get the current state of the entity as known to the underlying database, or null if there is no corresponding rowDeprecated.this will be removed: it provides too wide access, making it hard to optimise the internals for specific access needs.Get the entity instance associated with the given keygetEntity(EntityUniqueKey euk) Get an entity cached by unique key@Nullable org.hibernate.engine.internal.StatefulPersistenceContext.EntityHolderImplgetEntityHolder(EntityKey key) Doubly internalRetrieve theEntityEntryrepresentation of the given entity.getIndexInOwner(String entity, String property, Object childEntity, Map mergeMap) Search the persistence context for an index of the child object, given a collection roleRetrieve this persistence context's managed load context.getLoadedCollectionOwnerIdOrNull(PersistentCollection<?> collection) Get the ID for the entity that owned this persistent collection when it was loadedgetLoadedCollectionOwnerOrNull(PersistentCollection<?> collection) Get the entity that owned this persistent collection when it was loadedAccess to the natural-id helper for this persistence contextgetNaturalIdSnapshot(Object 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.intgetOwnerId(String entityName, String propertyName, Object childEntity, Map mergeMap) Searchthispersistence context for an associated entity instance which is considered the "owner" of the givenchildEntity, and return that owner's id value.Get an existing proxy by keyGet the session to which this persistence context is bound.getSnapshot(PersistentCollection<?> coll) Get the snapshot of the pre-flush collection statebooleanintCalled before cascadingvoidForce 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)protected voidinitializeNonLazyCollections(Consumer<PersistentCollection<?>> initializeAction) booleanWill entities and proxies that are loaded into this persistence context be made read-only by default?booleanisEntryFor(Object entity) Is there anEntityEntryregistration for this entity instance?booleanIs a flush cycle currently in process?booleanIs in a two-phase load?booleanbooleanisPropertyNull(EntityKey ownerKey, String propertyName) Is the association property belonging to the keyed entity null?booleanisReadOnly(Object entityOrProxy) Is the entity or proxy read-only?booleanbooleanA read-only iterator on all entities managed by this persistence contextnarrowProxy(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.voidpostLoad(JdbcValuesSourceProcessingState processingState, Consumer<EntityHolder> holderConsumer) Return the existing proxy associated with the givenEntityKey, or the argument (the entity associated with the key) if no proxy exists.proxyFor(EntityHolder holder) Return the existing proxy associated with the givenEntityHolder, or the entity if it contains no proxy.proxyFor(EntityHolder holder, EntityPersister persister) proxyFor(EntityPersister persister, EntityKey key, Object impl) Return the existing proxy associated with the givenEntityKey, or the third argument (the entity associated with the key) if no proxy exists.booleanTakes the given object and, if it represents a proxy, reassociates it with this event source.voidreassociateProxy(Object value, Object id) If a deleted entity instance is re-saved, and it has a proxy, we need to reset the identifier of the proxyProvides access to the entity/EntityEntry combos associated with the persistence context in a manner that is safe from reentrant access.voidvoidregisterInsertedKey(EntityPersister persister, Object id) Register keys inserted during the current transactionvoidRegisters anEntityKeyas nullifiable on thisPersistenceContext.voidremoveChildParent(Object child) Remove child/parent relation from cachevoidremoveCollectionByKey(CollectionKey collectionKey) Remove a collection-by-key mapping.removeCollectionEntry(PersistentCollection<?> collection) Remove aPersistentCollectionfrom thePersistenceContext.removeCollectionHolder(Object array) Remove the mapping of collection to holder during eviction of the owning entityvoidremoveEntity(EntityKey key) Remove an entity.@Nullable org.hibernate.engine.internal.StatefulPersistenceContext.EntityHolderImplremoveEntry(Object entity) Remove an entity entry from the session cacheremoveProxy(EntityKey key) Remove a proxy from the session cache.voidreplaceDelayedEntityIdentityInsertKeys(EntityKey oldKey, Object generatedId) voidreplaceEntityEntryRowId(Object entity, Object rowId) voidUsed by the owning session to explicitly control serialization of the persistence context.voidsetDefaultReadOnly(boolean defaultReadOnly) Change the default for entities and proxies loaded into this persistence context from modifiable to read-only mode, or from read-only mode to modifiable.voidsetEntryStatus(EntityEntry entry, Status status) Set the status of an entryvoidsetFlushing(boolean flushing) Called before and after the flush cyclevoidsetReadOnly(Object object, boolean readOnly) Set an unmodified persistent object to read-only mode, or a read-only object to modifiable mode.toString()Returns a string representation of the object.Get the entity instance underlying the given proxy, throwing an exception if the proxy is uninitialized.unproxyAndReassociate(Object maybeProxy) Possibly unproxy the given reference and reassociate it with the current session.Take ownership of a previously unowned collection, if one.booleanwasInsertedDuringTransaction(EntityPersister persister, Object id) Allows callers to check to see if the identified entity was inserted during the current transaction.
-
Constructor Details
-
Method Details
-
isStateless
public boolean isStateless()- Specified by:
isStatelessin interfacePersistenceContext
-
getSession
Description copied from interface:PersistenceContextGet the session to which this persistence context is bound.- Specified by:
getSessionin interfacePersistenceContext- Returns:
- The session.
-
getLoadContexts
Description copied from interface:PersistenceContextRetrieve this persistence context's managed load context.- Specified by:
getLoadContextsin interfacePersistenceContext- Returns:
- The load context
-
hasLoadContext
public boolean hasLoadContext()- Specified by:
hasLoadContextin interfacePersistenceContext
-
useUnownedCollection
Description copied from interface:PersistenceContextTake ownership of a previously unowned collection, if one. This method returnsnullif no such collection was previously added () or was previously removed.This should indicate the owner is being loaded and we are ready to "link" them.
- Specified by:
useUnownedCollectionin interfacePersistenceContext- Parameters:
key- The collection key for which to locate a collection collection- Returns:
- The unowned collection, or
null
-
getBatchFetchQueue
Description copied from interface:PersistenceContextGet theBatchFetchQueue, instantiating one if necessary.- Specified by:
getBatchFetchQueuein interfacePersistenceContext- Returns:
- The batch fetch queue in effect for this persistence context
-
clear
public void clear()Description copied from interface:PersistenceContextClear the state of the persistence context- Specified by:
clearin interfacePersistenceContext
-
isDefaultReadOnly
public boolean isDefaultReadOnly()Description copied from interface:PersistenceContextWill 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:
isDefaultReadOnlyin interfacePersistenceContext- Returns:
- true, loaded entities/proxies will be made read-only by default; false, loaded entities/proxies will be made modifiable by default.
- See Also:
-
setDefaultReadOnly
public void setDefaultReadOnly(boolean defaultReadOnly) Description copied from interface:PersistenceContextChange the default for entities and proxies loaded into this persistence context from modifiable to read-only mode, or from read-only mode to modifiable. 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:
setDefaultReadOnlyin interfacePersistenceContext- Parameters:
defaultReadOnly- true, the default for loaded entities/proxies is read-only; false, the default for loaded entities/proxies is modifiable- See Also:
-
setEntryStatus
Description copied from interface:PersistenceContextSet the status of an entry- Specified by:
setEntryStatusin interfacePersistenceContext- Parameters:
entry- The entry for which to set the statusstatus- The new status
-
afterTransactionCompletion
public void afterTransactionCompletion()Description copied from interface:PersistenceContextCalled after transactions end- Specified by:
afterTransactionCompletionin interfacePersistenceContext
-
getDatabaseSnapshot
Get the current state of the entity as known to the underlying database, or null if there is no corresponding rowGet the current state of the entity as known to the underlying database, or null if there is no corresponding row
- Specified by:
getDatabaseSnapshotin interfacePersistenceContext- Parameters:
id- The identifier of the entity for which to grab a snapshotpersister- The persister of the entity.- Returns:
- The entity's (non-cached) snapshot
- Throws:
HibernateException- See Also:
-
getNaturalIdSnapshot
Description copied from interface:PersistenceContextGet 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:
getNaturalIdSnapshotin interfacePersistenceContext- Parameters:
id- The identifier of the entity for which to grab a snapshotpersister- The persister of the entity.- Returns:
- The current (non-cached) snapshot of the entity's natural id state.
- Throws:
HibernateException
-
getCachedDatabaseSnapshot
Description copied from interface:PersistenceContextRetrieve the cached database snapshot for the requested entity key.This differs from
PersistenceContext.getDatabaseSnapshot(java.lang.Object, org.hibernate.persister.entity.EntityPersister)in two important respects:- no snapshot is obtained from the database if not already cached
- an entry of
PersistenceContext.NO_ROWhere is interpreted as an exception
- Specified by:
getCachedDatabaseSnapshotin interfacePersistenceContext- Parameters:
key- The entity key for which to retrieve the cached snapshot- Returns:
- The cached snapshot
-
claimEntityHolderIfPossible
public EntityHolder claimEntityHolderIfPossible(EntityKey key, Object entity, JdbcValuesSourceProcessingState processingState, EntityInitializer<?> initializer) Description copied from interface:PersistenceContextReturn an existing entity holder for the entity key, possibly creating one if necessary. Will claim the entity holder by registering the given entity initializer, if it isn't claimed yet.- Specified by:
claimEntityHolderIfPossiblein interfacePersistenceContext- Parameters:
key- The key under which to add an entityentity- The entity instance to addprocessingState- The processing state which initializes the entity if successfully claimedinitializer- The initializer to claim the entity instance
-
getEntityHolder
public @Nullable org.hibernate.engine.internal.StatefulPersistenceContext.EntityHolderImpl getEntityHolder(EntityKey key) - Specified by:
getEntityHolderin interfacePersistenceContext
-
containsEntityHolder
- Specified by:
containsEntityHolderin interfacePersistenceContext
-
postLoad
public void postLoad(JdbcValuesSourceProcessingState processingState, Consumer<EntityHolder> holderConsumer) - Specified by:
postLoadin interfacePersistenceContext
-
addEntity
Description copied from interface:PersistenceContextAdd a canonical mapping from entity key to entity instance- Specified by:
addEntityin interfacePersistenceContext- Parameters:
key- The key under which to add an entityentity- The entity instance to add
-
addEntityHolder
- Specified by:
addEntityHolderin interfacePersistenceContext
-
getEntity
Description copied from interface:PersistenceContextGet the entity instance associated with the given key- Specified by:
getEntityin interfacePersistenceContext- Parameters:
key- The key under which to look for an entity- Returns:
- The matching entity, or
null
-
containsEntity
Description copied from interface:PersistenceContextIs there an entity with the given key in the persistence context- Specified by:
containsEntityin interfacePersistenceContext- Parameters:
key- The key under which to look for an entity- Returns:
trueindicates an entity was found; otherwisefalse
-
removeEntity
Description copied from interface:PersistenceContextRemove an entity. Also clears up all other state associated with the entity aside from theEntityEntry- Specified by:
removeEntityin interfacePersistenceContext- Parameters:
key- The key whose matching entity should be removed- Returns:
- The matching entity
-
removeEntityHolder
public @Nullable org.hibernate.engine.internal.StatefulPersistenceContext.EntityHolderImpl removeEntityHolder(EntityKey key) - Specified by:
removeEntityHolderin interfacePersistenceContext
-
getEntity
Description copied from interface:PersistenceContextGet an entity cached by unique key- Specified by:
getEntityin interfacePersistenceContext- Parameters:
euk- The unique (non-primary) key under which to look for an entity- Returns:
- The located entity
-
addEntity
Description copied from interface:PersistenceContextAdd an entity to the cache by unique key- Specified by:
addEntityin interfacePersistenceContext- Parameters:
euk- The unique (non-primary) key under which to add an entityentity- The entity instance
-
getEntry
Description copied from interface:PersistenceContextRetrieve theEntityEntryrepresentation of the given entity.- Specified by:
getEntryin interfacePersistenceContext- Parameters:
entity- The entity instance for which to locate the corresponding entry- Returns:
- The entry
-
removeEntry
Description copied from interface:PersistenceContextRemove an entity entry from the session cache- Specified by:
removeEntryin interfacePersistenceContext- Parameters:
entity- The entity instance for which to remove the corresponding entry- Returns:
- The matching entry
-
isEntryFor
Description copied from interface:PersistenceContextIs there anEntityEntryregistration for this entity instance?- Specified by:
isEntryForin interfacePersistenceContext- Parameters:
entity- The entity instance for which to check for an entry- Returns:
trueindicates a matching entry was found.
-
getCollectionEntry
Description copied from interface:PersistenceContextGet the collection entry for a persistent collection- Specified by:
getCollectionEntryin interfacePersistenceContext- 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) Description copied from interface:PersistenceContextAdds an entity to the internal caches.- Specified by:
addEntityin interfacePersistenceContext
-
addEntry
public EntityEntry addEntry(Object entity, Status status, Object[] loadedState, Object rowId, Object id, Object version, LockMode lockMode, boolean existsInDatabase, EntityPersister persister, boolean disableVersionIncrement) Description copied from interface:PersistenceContextGenerates an appropriate EntityEntry instance and adds it to the event source's internal caches.- Specified by:
addEntryin interfacePersistenceContext
-
addReferenceEntry
-
containsCollection
Description copied from interface:PersistenceContextIs the given collection associated with this persistence context?- Specified by:
containsCollectionin interfacePersistenceContext
-
containsProxy
Description copied from interface:PersistenceContextIs the given proxy associated with this persistence context?- Specified by:
containsProxyin interfacePersistenceContext
-
reassociateIfUninitializedProxy
Description copied from interface:PersistenceContextTakes the given object and, if it represents a proxy, reassociates it with this event source.- Specified by:
reassociateIfUninitializedProxyin interfacePersistenceContext- Parameters:
value- The possible proxy to be reassociated.- Returns:
- Whether the passed value represented an actual proxy which got initialized.
- Throws:
MappingException
-
reassociateProxy
Description copied from interface:PersistenceContextIf a deleted entity instance is re-saved, and it has a proxy, we need to reset the identifier of the proxy- Specified by:
reassociateProxyin interfacePersistenceContext- Throws:
MappingException
-
unproxy
Description copied from interface:PersistenceContextGet 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:
unproxyin interfacePersistenceContext- Throws:
HibernateException
-
unproxyAndReassociate
Description copied from interface:PersistenceContextPossibly unproxy the given reference and reassociate it with the current session.- Specified by:
unproxyAndReassociatein interfacePersistenceContext- Parameters:
maybeProxy- The reference to be unproxied if it currently represents a proxy.- Returns:
- The unproxied instance.
- Throws:
HibernateException
-
checkUniqueness
Description copied from interface:PersistenceContextAttempts to check whether the given key represents an entity already loaded within the current session.- Specified by:
checkUniquenessin interfacePersistenceContextobject- 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 Description copied from interface:PersistenceContextIf 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:
narrowProxyin interfacePersistenceContext- 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 Description copied from interface:PersistenceContextReturn the existing proxy associated with the givenEntityKey, 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:
proxyForin interfacePersistenceContext- Throws:
HibernateException
-
proxyFor
Description copied from interface:PersistenceContextReturn the existing proxy associated with the givenEntityKey, or the argument (the entity associated with the key) if no proxy exists. (slower than the form above)- Specified by:
proxyForin interfacePersistenceContext- Throws:
HibernateException
-
proxyFor
Description copied from interface:PersistenceContextReturn the existing proxy associated with the givenEntityHolder, or the entity if it contains no proxy.- Specified by:
proxyForin interfacePersistenceContext- Throws:
HibernateException
-
proxyFor
Description copied from interface:PersistenceContext- Specified by:
proxyForin interfacePersistenceContext
-
addEnhancedProxy
Description copied from interface:PersistenceContextCross betweenPersistenceContext.addEntity(EntityKey, Object)andPersistenceContext.addProxy(EntityKey, Object)for use with enhancement-as-proxy- Specified by:
addEnhancedProxyin interfacePersistenceContext
-
getCollectionOwner
public Object getCollectionOwner(Object key, CollectionPersister collectionPersister) throws MappingException Description copied from interface:PersistenceContextGet the entity that owns this persistent collection- Specified by:
getCollectionOwnerin interfacePersistenceContext- Throws:
MappingException
-
getLoadedCollectionOwnerOrNull
Description copied from interface:PersistenceContextGet the entity that owned this persistent collection when it was loaded- Specified by:
getLoadedCollectionOwnerOrNullin interfacePersistenceContext- 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
Description copied from interface:PersistenceContextGet the ID for the entity that owned this persistent collection when it was loaded- Specified by:
getLoadedCollectionOwnerIdOrNullin interfacePersistenceContext- 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, Object id) Description copied from interface:PersistenceContextadd a collection we just loaded up (still needs initializing)- Specified by:
addUninitializedCollectionin interfacePersistenceContext
-
addUninitializedDetachedCollection
public void addUninitializedDetachedCollection(CollectionPersister persister, PersistentCollection<?> collection) Description copied from interface:PersistenceContextadd a detached uninitialized collection- Specified by:
addUninitializedDetachedCollectionin interfacePersistenceContext
-
addNewCollection
public void addNewCollection(CollectionPersister persister, PersistentCollection<?> collection) throws HibernateException Description copied from interface:PersistenceContextAdd a new collection (ie. a newly created one, just instantiated by the application, with no database state or snapshot)- Specified by:
addNewCollectionin interfacePersistenceContextcollection- The collection to be associated with the persistence context- Throws:
HibernateException
-
addInitializedDetachedCollection
public void addInitializedDetachedCollection(CollectionPersister collectionPersister, PersistentCollection<?> collection) throws HibernateException Description copied from interface:PersistenceContextadd 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:
addInitializedDetachedCollectionin interfacePersistenceContext- Throws:
HibernateException
-
addInitializedCollection
public CollectionEntry addInitializedCollection(CollectionPersister persister, PersistentCollection<?> collection, Object id) throws HibernateException Description copied from interface:PersistenceContextadd a collection we just pulled out of the cache (does not need initializing)- Specified by:
addInitializedCollectionin interfacePersistenceContext- Throws:
HibernateException
-
getCollection
Description copied from interface:PersistenceContextGet the collection instance associated with theCollectionKey- Specified by:
getCollectionin interfacePersistenceContext
-
addNonLazyCollection
Description copied from interface:PersistenceContextRegister a collection for non-lazy loading at the end of the two-phase load- Specified by:
addNonLazyCollectionin interfacePersistenceContext
-
initializeNonLazyCollections
Description copied from interface:PersistenceContextForce 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:
initializeNonLazyCollectionsin interfacePersistenceContext- Throws:
HibernateException
-
initializeNonLazyCollections
-
getCollectionHolder
Description copied from interface:PersistenceContextGet thePersistentCollectionobject for an array- Specified by:
getCollectionHolderin interfacePersistenceContext
-
addCollectionHolder
Description copied from interface:PersistenceContextRegister aPersistentCollectionobject 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:
addCollectionHolderin interfacePersistenceContext
-
removeCollectionHolder
Description copied from interface:PersistenceContextRemove the mapping of collection to holder during eviction of the owning entity- Specified by:
removeCollectionHolderin interfacePersistenceContext
-
getSnapshot
Description copied from interface:PersistenceContextGet the snapshot of the pre-flush collection state- Specified by:
getSnapshotin interfacePersistenceContext
-
getProxy
Description copied from interface:PersistenceContextGet an existing proxy by key- Specified by:
getProxyin interfacePersistenceContext
-
addProxy
Description copied from interface:PersistenceContextAdd a proxy to the session cache- Specified by:
addProxyin interfacePersistenceContext
-
removeProxy
Description copied from interface:PersistenceContextRemove 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:
removeProxyin interfacePersistenceContext- Parameters:
key- The key of the entity proxy to be removed- Returns:
- The proxy reference.
-
getEntitiesByKey
Deprecated.this will be removed: it provides too wide access, making it hard to optimise the internals for specific access needs. Consider using #iterateEntities instead.Description copied from interface:PersistenceContextDoubly internal- Specified by:
getEntitiesByKeyin interfacePersistenceContext
-
getEntityHoldersByKey
Description copied from interface:PersistenceContextDoubly internal- Specified by:
getEntityHoldersByKeyin interfacePersistenceContext
-
managedEntitiesIterator
Description copied from interface:PersistenceContextA read-only iterator on all entities managed by this persistence context- Specified by:
managedEntitiesIteratorin interfacePersistenceContext
-
getNumberOfManagedEntities
public int getNumberOfManagedEntities()- Specified by:
getNumberOfManagedEntitiesin interfacePersistenceContext
-
getCollectionEntries
Deprecated.We should not expose this directly: the other accessors that have been created as a replacement have better chances of skipping initializing this map, which is a good performance improvement.Description copied from interface:PersistenceContextDoubly internal- Specified by:
getCollectionEntriesin interfacePersistenceContext- Returns:
- the map of managed collection entries.
-
forEachCollectionEntry
public void forEachCollectionEntry(BiConsumer<PersistentCollection<?>, CollectionEntry> action, boolean concurrent) Description copied from interface:PersistenceContextExecute some action on each entry of the collectionEntries map, optionally iterating on a defensive copy.- Specified by:
forEachCollectionEntryin interfacePersistenceContext- Parameters:
action- the lambda to apply on each PersistentCollection,CollectionEntry map entry of the PersistenceContext.concurrent- set this to false for improved efficiency, but that would make it illegal to make changes to the underlying collectionEntries map.
-
getCollectionsByKey
Description copied from interface:PersistenceContextGet the mapping from collection key to collection instance- Specified by:
getCollectionsByKeyin interfacePersistenceContext
-
getCascadeLevel
public int getCascadeLevel()Description copied from interface:PersistenceContextHow deep are we cascaded?- Specified by:
getCascadeLevelin interfacePersistenceContext
-
incrementCascadeLevel
public int incrementCascadeLevel()Description copied from interface:PersistenceContextCalled before cascading- Specified by:
incrementCascadeLevelin interfacePersistenceContext
-
decrementCascadeLevel
public int decrementCascadeLevel()Description copied from interface:PersistenceContextCalled after cascading- Specified by:
decrementCascadeLevelin interfacePersistenceContext
-
isFlushing
public boolean isFlushing()Description copied from interface:PersistenceContextIs a flush cycle currently in process?- Specified by:
isFlushingin interfacePersistenceContext
-
setFlushing
public void setFlushing(boolean flushing) Description copied from interface:PersistenceContextCalled before and after the flush cycle- Specified by:
setFlushingin interfacePersistenceContext
-
isRemovingOrphanBeforeUpates
public boolean isRemovingOrphanBeforeUpates() -
beginRemoveOrphanBeforeUpdates
public void beginRemoveOrphanBeforeUpdates() -
endRemoveOrphanBeforeUpdates
public void endRemoveOrphanBeforeUpdates() -
beforeLoad
public void beforeLoad()Call this before beginning a two-phase load- Specified by:
beforeLoadin interfacePersistenceContext
-
afterLoad
public void afterLoad()Call this after finishing a two-phase load- Specified by:
afterLoadin interfacePersistenceContext
-
isLoadFinished
public boolean isLoadFinished()Description copied from interface:PersistenceContextIs in a two-phase load?- Specified by:
isLoadFinishedin interfacePersistenceContext
-
toString
Description copied from interface:PersistenceContextReturns a string representation of the object.- Specified by:
toStringin interfacePersistenceContext- Overrides:
toStringin classObject- Returns:
- a string representation of the object.
-
reentrantSafeEntityEntries
Description copied from interface:PersistenceContextProvides access to the entity/EntityEntry combos associated with the persistence context in a manner that is safe from reentrant access. Specifically, it is safe from additions/removals while iterating.- Specified by:
reentrantSafeEntityEntriesin interfacePersistenceContext
-
getOwnerId
Description copied from interface:PersistenceContextSearchthispersistence context for an associated entity instance which is considered the "owner" of the givenchildEntity, 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
mergeMapwhich 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:
getOwnerIdin interfacePersistenceContext- Parameters:
entityName- The entity name for the entity type which would own the childpropertyName- 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
Description copied from interface:PersistenceContextSearch the persistence context for an index of the child object, given a collection role- Specified by:
getIndexInOwnerin interfacePersistenceContext
-
addNullProperty
Description copied from interface:PersistenceContextRecord the fact that the association belonging to the keyed entity is null.- Specified by:
addNullPropertyin interfacePersistenceContext
-
isPropertyNull
Description copied from interface:PersistenceContextIs the association property belonging to the keyed entity null?- Specified by:
isPropertyNullin interfacePersistenceContext
-
isReadOnly
Description copied from interface:PersistenceContextIs 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:
isReadOnlyin interfacePersistenceContext- Parameters:
entityOrProxy- an entity or proxy- Returns:
trueif the object is read-only; otherwisefalseto indicate that the object is modifiable.
-
setReadOnly
Description copied from interface:PersistenceContextSet 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:
setReadOnlyin interfacePersistenceContext- Parameters:
object- an entity or proxyreadOnly- iftrue, the entity or proxy is made read-only; otherwise, the entity or proxy is made modifiable.- See Also:
-
replaceDelayedEntityIdentityInsertKeys
- Specified by:
replaceDelayedEntityIdentityInsertKeysin interfacePersistenceContext
-
replaceEntityEntryRowId
- Specified by:
replaceEntityEntryRowIdin interfacePersistenceContext
-
serialize
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 Used by the owning session to explicitly control deserialization of the persistence context.- Parameters:
ois- The stream from which the persistence context should be readsession- The owning session- Returns:
- The deserialized StatefulPersistenceContext
- Throws:
IOException- deserialization errors.ClassNotFoundException- deserialization errors.
-
addChildParent
Description copied from interface:PersistenceContextAdd a child/parent relation to cache for cascading op- Specified by:
addChildParentin interfacePersistenceContext- Parameters:
child- The child of the relationshipparent- The parent of the relationship
-
removeChildParent
Description copied from interface:PersistenceContextRemove child/parent relation from cache- Specified by:
removeChildParentin interfacePersistenceContext- Parameters:
child- The child to be removed.
-
registerInsertedKey
Description copied from interface:PersistenceContextRegister keys inserted during the current transaction- Specified by:
registerInsertedKeyin interfacePersistenceContext- Parameters:
persister- The entity persisterid- The id
-
wasInsertedDuringTransaction
Description copied from interface:PersistenceContextAllows callers to check to see if the identified entity was inserted during the current transaction.- Specified by:
wasInsertedDuringTransactionin interfacePersistenceContext- Parameters:
persister- The entity persisterid- The id- Returns:
- True if inserted during this transaction, false otherwise.
-
containsNullifiableEntityKey
Description copied from interface:PersistenceContextChecks if a certainEntityKeywas registered as nullifiable on thisPersistenceContext.- Specified by:
containsNullifiableEntityKeyin interfacePersistenceContext- Parameters:
sek- a supplier for the EntityKey; this allows to not always needing to create the key; for example if the map is known to be empty there is no need to create one to check.- Returns:
- true if the EntityKey had been registered before using
PersistenceContext.registerNullifiableEntityKey(EntityKey) - See Also:
-
registerNullifiableEntityKey
Description copied from interface:PersistenceContextRegisters anEntityKeyas nullifiable on thisPersistenceContext.- Specified by:
registerNullifiableEntityKeyin interfacePersistenceContext
-
isNullifiableEntityKeysEmpty
public boolean isNullifiableEntityKeysEmpty()- Specified by:
isNullifiableEntityKeysEmptyin interfacePersistenceContext- Returns:
- true if no
EntityKeywas registered as nullifiable on thisPersistenceContext. - See Also:
-
containsDeletedUnloadedEntityKey
- Specified by:
containsDeletedUnloadedEntityKeyin interfacePersistenceContext
-
registerDeletedUnloadedEntityKey
- Specified by:
registerDeletedUnloadedEntityKeyin interfacePersistenceContext
-
removeDeletedUnloadedEntityKey
- Specified by:
removeDeletedUnloadedEntityKeyin interfacePersistenceContext
-
containsDeletedUnloadedEntityKeys
public boolean containsDeletedUnloadedEntityKeys()- Specified by:
containsDeletedUnloadedEntityKeysin interfacePersistenceContext
-
getCollectionEntriesSize
public int getCollectionEntriesSize()Description copied from interface:PersistenceContextThe size of the internal map storing all collection entries. (The map is not exposed directly, but the size is often useful)- Specified by:
getCollectionEntriesSizein interfacePersistenceContext- Returns:
- the size
-
removeCollectionEntry
Description copied from interface:PersistenceContextRemove aPersistentCollectionfrom thePersistenceContext.- Specified by:
removeCollectionEntryin interfacePersistenceContext- Parameters:
collection- the collection to remove- Returns:
- the matching
CollectionEntry, if any was removed.
-
clearCollectionsByKey
public void clearCollectionsByKey()Description copied from interface:PersistenceContextRemove all state of the collections-by-key map.- Specified by:
clearCollectionsByKeyin interfacePersistenceContext
-
addCollectionByKey
public PersistentCollection<?> addCollectionByKey(CollectionKey collectionKey, PersistentCollection<?> persistentCollection) Description copied from interface:PersistenceContextAdds a collection in the collections-by-key map.- Specified by:
addCollectionByKeyin interfacePersistenceContext- Returns:
- the previous collection, it the key was already mapped.
-
removeCollectionByKey
Description copied from interface:PersistenceContextRemove a collection-by-key mapping.- Specified by:
removeCollectionByKeyin interfacePersistenceContext- Parameters:
collectionKey- the key to clear
-
getNaturalIdResolutions
Description copied from interface:PersistenceContextAccess to the natural-id helper for this persistence context- Specified by:
getNaturalIdResolutionsin interfacePersistenceContext- Returns:
- This persistence context's natural-id helper
-
detachEntity
Description copied from interface:PersistenceContextRemove theEntityHolderand set its state to DETACHED- Specified by:
detachEntityin interfacePersistenceContext
-