Top Description Methods
org.hibernate.persister.collection

public Interface CollectionPersister

extends Restrictable
Known Direct Subinterfaces
org.hibernate.persister.collection.QueryableCollection
Known Direct Implementers
org.hibernate.persister.collection.AbstractCollectionPersister
Imports
java.util.Comparator, .Map, .Set, java.util.function.Consumer, org.hibernate.Filter, .HibernateException, .MappingException, org.hibernate.cache.spi.access.CollectionDataAccess, org.hibernate.cache.spi.entry.CacheEntryStructure, org.hibernate.collection.spi.CollectionSemantics, .PersistentCollection, org.hibernate.engine.spi.LoadQueryInfluencers, .SessionFactoryImplementor, .SharedSessionContractImplementor, org.hibernate.id.IdentifierGenerator, org.hibernate.metadata.CollectionMetadata, org.hibernate.metamodel.CollectionClassification, org.hibernate.metamodel.mapping.PluralAttributeMapping, .Restrictable, org.hibernate.metamodel.model.domain.NavigableRole, org.hibernate.metamodel.spi.RuntimeModelCreationContext, org.hibernate.persister.entity.EntityPersister, org.hibernate.sql.ast.spi.SqlAstCreationState, org.hibernate.sql.ast.tree.from.TableGroup, org.hibernate.sql.ast.tree.predicate.Predicate, org.hibernate.generator.BeforeExecutionGenerator, org.hibernate.type.CollectionType, .Type

A strategy for persisting a mapped collection role. A CollectionPersister orchestrates rendering of SQL statements corresponding to basic lifecycle events, including insert, update, and delete statements, and their execution via JDBC.

Concrete implementations of this interface handle one-to-many and many-to-many association cardinalities, and to a certain extent abstract the details of those mappings from collaborators.

Note that an instance of PersistentCollection may change roles. This object implements persistence of a collection instance while the instance is referenced in a particular role.

This interface defines a contract between the persistence strategy and the actual persistent collection framework and session. It does not define operations that are required for querying collections, nor for loading by outer join. Implementations are highly coupled to the PersistentCollection hierarchy, since double dispatch is used to load and update collection elements.

Unless a custom org.hibernate.persister.spi.PersisterFactory is used, it is expected that implementations of CollectionPersister define a constructor accepting the following arguments:

  1. org.hibernate.mapping.Collection - The metadata about the collection to be handled by the persister,
  2. CollectionDataAccess - the second level caching strategy for this collection, and
  3. RuntimeModelCreationContext - access to additional information useful while constructing the persister.
Author
Gavin King
See Also
PersistentCollection, PluralAttributeMapping

Method Summary

Modifier and TypeMethod and Description
public void
applyBaseManyToManyRestrictions(Consumer<Predicate> predicateConsumer, TableGroup tableGroup, boolean useQualifier, Map<String, Filter> enabledFilters, Set<String> treatAsDeclarations, SqlAstCreationState creationState)

public void
deleteRows(PersistentCollection<?> collection, Object key, SharedSessionContractImplementor session)

Delete the persistent state of any elements that were removed from the collection

public boolean
public default PluralAttributeMapping
public default int
public CollectionDataAccess
getCacheAccessStrategy()

Access to the collection's cache region

public CacheEntryStructure
getCacheEntryStructure()

Get the structure used to store data into the collection's cache region

public CollectionMetadata
getCollectionMetadata()

Deprecated since 6.0. This operation is no longer called by Hibernate.
Get the user-visible metadata for the collection (optional operation)
public CollectionSemantics<?, ?>
public String[]
getCollectionSpaces()

Get the "space" that holds the persistent state

public CollectionType
getCollectionType()

Deprecated for removal. Hibernate is moving away from Type.
Get the associated Type
public Object
public Class<?>
getElementClass()

Return the element class of an array, or null otherwise

public String[]

Returns:

The key column aliases.
getElementColumnAliases
(String
The suffix to use in the element column alias generation.
suffix
)

Deprecated for removal since 6. Read-by-position makes this irrelevant. Currently still used by org.hibernate.query.sql.internal.SQLQueryParser
Generates the collection's element column aliases, based on the given suffix.
public Type
getElementType()

Deprecated for removal. Hibernate is moving away from Type.
Get the "element" type
public SessionFactoryImplementor
getFactory()

Deprecated as a consequence of SessionFactoryImplementor being deprecated.
public default BeforeExecutionGenerator
getGenerator()

Get the surrogate key generation strategy (optional operation)

public String

Returns:

The key column aliases.
getIdentifierColumnAlias
(String
The suffix to use in the key column alias generation.
suffix
)

Deprecated for removal since 6. Read-by-position makes this irrelevant. Currently still used by org.hibernate.query.sql.internal.SQLQueryParser
Generates the collection's identifier column aliases, based on the given suffix.
public IdentifierGenerator
getIdentifierGenerator()

Deprecated use getGenerator()
Get the surrogate key generation strategy (optional operation)
public Type
getIdentifierType()

Deprecated for removal. Hibernate is moving away from Type.
Get the type of the surrogate key
public String[]

Returns:

The key column aliases, or null if not indexed.
getIndexColumnAliases
(String
The suffix to use in the index column alias generation.
suffix
)

Deprecated for removal since 6. Read-by-position makes this irrelevant. Currently still used by org.hibernate.query.sql.internal.SQLQueryParser
Generates the collection's index column aliases, based on the given suffix.
public Type
getIndexType()

Deprecated for removal. Hibernate is moving away from Type.
Get the "index" type for a list or map (optional operation)
public String[]

Returns:

The key column aliases.
getKeyColumnAliases
(String
The suffix to use in the key column alias generation.
suffix
)

Deprecated for removal since 6. Read-by-position makes this irrelevant. Currently still used by org.hibernate.query.sql.internal.SQLQueryParser
Generates the collection's key column aliases, based on the given suffix.
public Type
getKeyType()

Deprecated for removal. Hibernate is moving away from Type.
Get the "key" type (the type of the foreign key)
public String
getManyToManyFilterFragment(TableGroup tableGroup, Map<String, Filter> enabledFilters)

public String

Returns:

the name of the property this collection is mapped by
getMappedByProperty
()

public NavigableRole
getNavigableRole()

The NavigableRole for this collection.

public EntityPersister
getOwnerEntityPersister()

Get the persister of the entity that "owns" this collection

public default String
public int
public Comparator<?>
getSortingComparator()

For sorted collections, the comparator to use.

public boolean
hasCache()

Is this collection role cacheable

public boolean
hasIndex()

Is this an "indexed" collection?

public boolean
public boolean
hasOrdering()

Is this an ordered collection?

public boolean
hasOrphanDelete()

Does this collection implement "orphan delete"?

public boolean
public void
initialize(Object key, SharedSessionContractImplementor session)

Initialize the given collection with the given key

public void
insertRows(PersistentCollection<?> collection, Object key, SharedSessionContractImplementor session)

Insert the persistent state of any new collection elements

public default boolean
public boolean
public default boolean
public default boolean
public boolean
isArray()

Is this an array?

public default boolean
public boolean
isCascadeDeleteEnabled()

Is cascade delete handled by the database-level foreign key constraint definition?

public default boolean
public boolean
isInverse()

Is this collection "inverse", so state changes are not propagated to the database.

public boolean
isLazy()

Is this collection lazily initialized?

public boolean
isManyToMany()

Is this a many-to-many association?

public boolean
isMutable()

Can the elements of this collection change?

public boolean
isOneToMany()

Is this a one-to-many association?

public boolean
isPrimitiveArray()

Is this an array or primitive values?

public default boolean
public boolean
isVersioned()

Does this collection cause version increment of the owning entity?

public default boolean
needsRemove()

Whether remove(Object, SharedSessionContractImplementor) might actually do something, or if it is definitely a no-op.

public void
public void
processQueuedOps(PersistentCollection<?> collection, Object key, SharedSessionContractImplementor session)

Process queued operations within the PersistentCollection.

public void
recreate(PersistentCollection<?> collection, Object key, SharedSessionContractImplementor session)

(Re)create the collection's persistent state

public void
remove(Object id, SharedSessionContractImplementor session)

Completely remove the persistent state of the collection

public void
updateRows(PersistentCollection<?> collection, Object key, SharedSessionContractImplementor session)

Update the persistent state of any elements that were modified

Inherited from org.hibernate.metamodel.mapping.Restrictable:
applyBaseRestrictions

Method Detail

applyBaseManyToManyRestrictionsback to summary
public void applyBaseManyToManyRestrictions(Consumer<Predicate> predicateConsumer, TableGroup tableGroup, boolean useQualifier, Map<String, Filter> enabledFilters, Set<String> treatAsDeclarations, SqlAstCreationState creationState)
deleteRowsback to summary
public void deleteRows(PersistentCollection<?> collection, Object key, SharedSessionContractImplementor session)

Delete the persistent state of any elements that were removed from the collection

elementExistsback to summary
public boolean elementExists(Object key, Object element, SharedSessionContractImplementor session)
getAttributeMappingback to summary
public default PluralAttributeMapping getAttributeMapping()
getBatchSizeback to summary
public default int getBatchSize()
getCacheAccessStrategyback to summary
public CollectionDataAccess getCacheAccessStrategy()

Access to the collection's cache region

getCacheEntryStructureback to summary
public CacheEntryStructure getCacheEntryStructure()

Get the structure used to store data into the collection's cache region

getCollectionMetadataback to summary
public CollectionMetadata getCollectionMetadata()

Deprecated

since 6.0.

This operation is no longer called by Hibernate.

Get the user-visible metadata for the collection (optional operation)

Annotations
@Deprecated
since:6.0
getCollectionSemanticsback to summary
public CollectionSemantics<?, ?> getCollectionSemantics()
getCollectionSpacesback to summary
public String[] getCollectionSpaces()

Get the "space" that holds the persistent state

getCollectionTypeback to summary
public CollectionType getCollectionType()

Deprecated

for removal.

Hibernate is moving away from Type. Corresponding mapping metamodel calls should be used instead - here (generally), PluralAttributeMapping

Get the associated Type

Annotations
@Deprecated
forRemoval:true
getElementByIndexback to summary
public Object getElementByIndex(Object key, Object index, SharedSessionContractImplementor session, Object owner)
getElementClassback to summary
public Class<?> getElementClass()

Return the element class of an array, or null otherwise

getElementColumnAliasesback to summary
public String[] getElementColumnAliases(String suffix)

Deprecated

for removal since 6.

Read-by-position makes this irrelevant. Currently still used by org.hibernate.query.sql.internal.SQLQueryParser

Generates the collection's element column aliases, based on the given suffix.

Parameters
suffix:String

The suffix to use in the element column alias generation.

Returns:String[]

The key column aliases.

Annotations
@Deprecated
since:6
forRemoval:true
getElementTypeback to summary
public Type getElementType()

Deprecated

for removal.

Hibernate is moving away from Type. Corresponding mapping metamodel calls should be used instead - here, PluralAttributeMapping#getElementDescriptor()

Get the "element" type

Annotations
@Deprecated
forRemoval:true
getFactoryback to summary
public SessionFactoryImplementor getFactory()

Deprecated

as a consequence of SessionFactoryImplementor being deprecated. See corresponding docs for further information.

getGeneratorback to summary
public default BeforeExecutionGenerator getGenerator()

Get the surrogate key generation strategy (optional operation)

getIdentifierColumnAliasback to summary
public String getIdentifierColumnAlias(String suffix)

Deprecated

for removal since 6.

Read-by-position makes this irrelevant. Currently still used by org.hibernate.query.sql.internal.SQLQueryParser

Generates the collection's identifier column aliases, based on the given suffix.

Parameters
suffix:String

The suffix to use in the key column alias generation.

Returns:String

The key column aliases.

Annotations
@Deprecated
since:6
forRemoval:true
getIdentifierGeneratorback to summary
public IdentifierGenerator getIdentifierGenerator()

Deprecated

use getGenerator()

Get the surrogate key generation strategy (optional operation)

Annotations
@Deprecated
getIdentifierTypeback to summary
public Type getIdentifierType()

Deprecated

for removal.

Hibernate is moving away from Type. Corresponding mapping metamodel calls should be used instead - here, PluralAttributeMapping#getIdentifierDescriptor()

Get the type of the surrogate key

Annotations
@Deprecated
forRemoval:true
getIndexColumnAliasesback to summary
public String[] getIndexColumnAliases(String suffix)

Deprecated

for removal since 6.

Read-by-position makes this irrelevant. Currently still used by org.hibernate.query.sql.internal.SQLQueryParser

Generates the collection's index column aliases, based on the given suffix.

Parameters
suffix:String

The suffix to use in the index column alias generation.

Returns:String[]

The key column aliases, or null if not indexed.

Annotations
@Deprecated
since:6
forRemoval:true
getIndexTypeback to summary
public Type getIndexType()

Deprecated

for removal.

Hibernate is moving away from Type. Corresponding mapping metamodel calls should be used instead - here, PluralAttributeMapping#getIndexDescriptor()

Get the "index" type for a list or map (optional operation)

Annotations
@Deprecated
forRemoval:true
getKeyColumnAliasesback to summary
public String[] getKeyColumnAliases(String suffix)

Deprecated

for removal since 6.

Read-by-position makes this irrelevant. Currently still used by org.hibernate.query.sql.internal.SQLQueryParser

Generates the collection's key column aliases, based on the given suffix.

Parameters
suffix:String

The suffix to use in the key column alias generation.

Returns:String[]

The key column aliases.

Annotations
@Deprecated
since:6
forRemoval:true
getKeyTypeback to summary
public Type getKeyType()

Deprecated

for removal.

Hibernate is moving away from Type. Corresponding mapping metamodel calls should be used instead - here, PluralAttributeMapping#getKeyDescriptor()

Get the "key" type (the type of the foreign key)

Annotations
@Deprecated
forRemoval:true
getManyToManyFilterFragmentback to summary
public String getManyToManyFilterFragment(TableGroup tableGroup, Map<String, Filter> enabledFilters)
getMappedByPropertyback to summary
public String getMappedByProperty()
Returns:String

the name of the property this collection is mapped by

getNavigableRoleback to summary
public NavigableRole getNavigableRole()

The NavigableRole for this collection.

getOwnerEntityPersisterback to summary
public EntityPersister getOwnerEntityPersister()

Get the persister of the entity that "owns" this collection

getRoleback to summary
public default String getRole()
getSizeback to summary
public int getSize(Object key, SharedSessionContractImplementor session)
getSortingComparatorback to summary
public Comparator<?> getSortingComparator()

For sorted collections, the comparator to use. Non-parameterized because for SORTED_SET the elements are compared but for SORTED_MAP the keys are compared

See Also
CollectionClassification#SORTED_MAP, CollectionClassification#SORTED_SET
hasCacheback to summary
public boolean hasCache()

Is this collection role cacheable

hasIndexback to summary
public boolean hasIndex()

Is this an "indexed" collection? (list or map)

hasManyToManyOrderingback to summary
public boolean hasManyToManyOrdering()
hasOrderingback to summary
public boolean hasOrdering()

Is this an ordered collection? (An ordered collection is ordered by the initialization operation, not by sorting that happens in memory, as in the case of a sorted collection.)

hasOrphanDeleteback to summary
public boolean hasOrphanDelete()

Does this collection implement "orphan delete"?

indexExistsback to summary
public boolean indexExists(Object key, Object index, SharedSessionContractImplementor session)
initializeback to summary
public void initialize(Object key, SharedSessionContractImplementor session) throws HibernateException

Initialize the given collection with the given key

insertRowsback to summary
public void insertRows(PersistentCollection<?> collection, Object key, SharedSessionContractImplementor session)

Insert the persistent state of any new collection elements

isAffectedByEnabledFetchProfilesback to summary
public default boolean isAffectedByEnabledFetchProfiles(LoadQueryInfluencers influencers)
isAffectedByEnabledFiltersback to summary
public boolean isAffectedByEnabledFilters(SharedSessionContractImplementor session)
isAffectedByEnabledFiltersback to summary
public default boolean isAffectedByEnabledFilters(LoadQueryInfluencers influencers)
isAffectedByEntityGraphback to summary
public default boolean isAffectedByEntityGraph(LoadQueryInfluencers influencers)
isArrayback to summary
public boolean isArray()

Is this an array?

isBatchLoadableback to summary
public default boolean isBatchLoadable()
isCascadeDeleteEnabledback to summary
public boolean isCascadeDeleteEnabled()

Is cascade delete handled by the database-level foreign key constraint definition?

isExtraLazyback to summary
public default boolean isExtraLazy()
isInverseback to summary
public boolean isInverse()

Is this collection "inverse", so state changes are not propagated to the database.

isLazyback to summary
public boolean isLazy()

Is this collection lazily initialized?

isManyToManyback to summary
public boolean isManyToMany()

Is this a many-to-many association? Note that this is mainly a convenience feature as the single persister does not contain all the information needed to handle a many-to-many itself, as internally it is looked at as two many-to-ones.

isMutableback to summary
public boolean isMutable()

Can the elements of this collection change?

isOneToManyback to summary
public boolean isOneToMany()

Is this a one-to-many association?

isPrimitiveArrayback to summary
public boolean isPrimitiveArray()

Is this an array or primitive values?

isSubselectLoadableback to summary
public default boolean isSubselectLoadable()
isVersionedback to summary
public boolean isVersioned()

Does this collection cause version increment of the owning entity?

needsRemoveback to summary
public default boolean needsRemove()

Whether remove(Object, SharedSessionContractImplementor) might actually do something, or if it is definitely a no-op.

postInstantiateback to summary
public void postInstantiate() throws MappingException
processQueuedOpsback to summary
public void processQueuedOps(PersistentCollection<?> collection, Object key, SharedSessionContractImplementor session)

Process queued operations within the PersistentCollection.

recreateback to summary
public void recreate(PersistentCollection<?> collection, Object key, SharedSessionContractImplementor session)

(Re)create the collection's persistent state

removeback to summary
public void remove(Object id, SharedSessionContractImplementor session)

Completely remove the persistent state of the collection

updateRowsback to summary
public void updateRows(PersistentCollection<?> collection, Object key, SharedSessionContractImplementor session)

Update the persistent state of any elements that were modified