public interface

PersistentCollection

org.hibernate.collection.PersistentCollection
Known Indirect Subclasses

Class Overview

Persistent collections are treated as value objects by Hibernate. ie. they have no independent existence beyond the object holding a reference to them. Unlike instances of entity classes, they are automatically deleted when unreferenced and automatically become persistent when held by a persistent object. Collections can be passed between different objects (change "roles") and this might cause their elements to move from one database table to another.

Hibernate "wraps" a java collection in an instance of PersistentCollection. This mechanism is designed to support tracking of changes to the collection's persistent state and lazy instantiation of collection elements. The downside is that only certain abstract collection types are supported and any extra semantics are lost

Applications should never use classes in this package directly, unless extending the "framework" here.

Changes to structure of the collection are recorded by the collection calling back to the session. Changes to mutable elements (ie. composite elements) are discovered by cloning their state when the collection is initialized and comparing at flush time.

Summary

Public Methods
abstract boolean afterInitialize()
Called after initializing from cache
abstract void afterRowInsert(CollectionPersister persister, Object entry, int i)
Called after inserting a row, to fetch the natively generated id
abstract void beforeInitialize(CollectionPersister persister, int anticipatedSize)
Called before any elements are read into the collection, allowing appropriate initializations to occur.
abstract void beginRead()
Called just before reading any rows from the JDBC result set
abstract void clearDirty()
Clear the dirty flag, after flushing changes to the database.
abstract void dirty()
Mark the collection as dirty
abstract Serializable disassemble(CollectionPersister persister)
Disassemble the collection, ready for the cache
abstract boolean empty()
Is the collection empty? (don't try to initialize the collection)
abstract boolean endRead()
Called after reading all rows from the JDBC result set
abstract Iterator entries(CollectionPersister persister)
Iterate all collection entries, during update of the database
abstract boolean entryExists(Object entry, int i)
Does an element exist at this entry in the collection?
abstract boolean equalsSnapshot(CollectionPersister persister)
Does the current state exactly match the snapshot?
abstract void forceInitialization()
To be called internally by the session, forcing immediate initialization.
abstract Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula)
Get all the elements that need deleting
abstract Object getElement(Object entry)
Get the value of the given collection entry
abstract Object getIdentifier(Object entry, int i)
Get the index of the given collection entry
abstract Object getIndex(Object entry, int i, CollectionPersister persister)
Get the index of the given collection entry
abstract Serializable getKey()
Get the current collection key value
abstract Collection getOrphans(Serializable snapshot, String entityName)
get all "orphaned" elements
abstract Object getOwner()
Get the owning entity.
abstract Collection getQueuedOrphans(String entityName)
Get the "queued" orphans
abstract String getRole()
Get the current role name
abstract Serializable getSnapshot(CollectionPersister persister)
Return a new snapshot of the current state of the collection
abstract Object getSnapshotElement(Object entry, int i)
Get the snapshot value of the given collection entry
abstract Serializable getStoredSnapshot()
Get the snapshot cached by the collection instance
abstract Object getValue()
return the user-visible collection (or array) instance
abstract boolean hasQueuedOperations()
Does this instance have any "queued" additions?
abstract void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner)
Read the state of the collection from a disassembled cached value
abstract boolean isDirectlyAccessible()
Could the application possibly have a direct reference to the underlying collection implementation?
abstract boolean isDirty()
Is the collection dirty? Note that this is only reliable during the flush cycle, after the collection elements are dirty checked against the snapshot.
abstract boolean isRowUpdatePossible()
abstract boolean isSnapshotEmpty(Serializable snapshot)
Is the snapshot empty?
abstract boolean isUnreferenced()
Is the collection unreferenced?
abstract boolean isWrapper(Object collection)
Is this the wrapper for the given underlying collection instance?
abstract boolean needsInserting(Object entry, int i, Type elemType)
Do we need to insert this element?
abstract boolean needsRecreate(CollectionPersister persister)
Do we need to completely recreate this collection when it changes?
abstract boolean needsUpdating(Object entry, int i, Type elemType)
Do we need to update this element?
abstract void postAction()
After flushing, clear any "queued" additions, since the database state is now synchronized with the memory state.
abstract void preInsert(CollectionPersister persister)
Called before inserting rows, to ensure that any surrogate keys are fully generated
abstract Iterator queuedAdditionIterator()
Iterate the "queued" additions
abstract Object readFrom(ResultSet rs, CollectionPersister role, CollectionAliases descriptor, Object owner)
Read a row from the JDBC result set
abstract boolean setCurrentSession(SessionImplementor session)
Associate the collection with the given session.
abstract void setOwner(Object entity)
Set the reference to the owning entity
abstract void setSnapshot(Serializable key, String role, Serializable snapshot)
After flushing, re-init snapshot state.
abstract boolean unsetSession(SessionImplementor currentSession)
Disassociate this collection from the given session.
abstract boolean wasInitialized()
Is this instance initialized?

Public Methods

public abstract boolean afterInitialize ()

Called after initializing from cache

public abstract void afterRowInsert (CollectionPersister persister, Object entry, int i)

Called after inserting a row, to fetch the natively generated id

public abstract void beforeInitialize (CollectionPersister persister, int anticipatedSize)

Called before any elements are read into the collection, allowing appropriate initializations to occur.

Parameters
persister The underlying collection persister.
anticipatedSize The anticipated size of the collection after initilization is complete.

public abstract void beginRead ()

Called just before reading any rows from the JDBC result set

public abstract void clearDirty ()

Clear the dirty flag, after flushing changes to the database.

public abstract void dirty ()

Mark the collection as dirty

public abstract Serializable disassemble (CollectionPersister persister)

Disassemble the collection, ready for the cache

public abstract boolean empty ()

Is the collection empty? (don't try to initialize the collection)

public abstract boolean endRead ()

Called after reading all rows from the JDBC result set

public abstract Iterator entries (CollectionPersister persister)

Iterate all collection entries, during update of the database

public abstract boolean entryExists (Object entry, int i)

Does an element exist at this entry in the collection?

public abstract boolean equalsSnapshot (CollectionPersister persister)

Does the current state exactly match the snapshot?

public abstract void forceInitialization ()

To be called internally by the session, forcing immediate initialization.

public abstract Iterator getDeletes (CollectionPersister persister, boolean indexIsFormula)

Get all the elements that need deleting

public abstract Object getElement (Object entry)

Get the value of the given collection entry

public abstract Object getIdentifier (Object entry, int i)

Get the index of the given collection entry

public abstract Object getIndex (Object entry, int i, CollectionPersister persister)

Get the index of the given collection entry

Parameters
persister it was more elegant before we added this...

public abstract Serializable getKey ()

Get the current collection key value

public abstract Collection getOrphans (Serializable snapshot, String entityName)

get all "orphaned" elements

public abstract Object getOwner ()

Get the owning entity. Note that the owner is only set during the flush cycle, and when a new collection wrapper is created while loading an entity.

public abstract Collection getQueuedOrphans (String entityName)

Get the "queued" orphans

public abstract String getRole ()

Get the current role name

public abstract Serializable getSnapshot (CollectionPersister persister)

Return a new snapshot of the current state of the collection

public abstract Object getSnapshotElement (Object entry, int i)

Get the snapshot value of the given collection entry

public abstract Serializable getStoredSnapshot ()

Get the snapshot cached by the collection instance

public abstract Object getValue ()

return the user-visible collection (or array) instance

public abstract boolean hasQueuedOperations ()

Does this instance have any "queued" additions?

public abstract void initializeFromCache (CollectionPersister persister, Serializable disassembled, Object owner)

Read the state of the collection from a disassembled cached value

public abstract boolean isDirectlyAccessible ()

Could the application possibly have a direct reference to the underlying collection implementation?

public abstract boolean isDirty ()

Is the collection dirty? Note that this is only reliable during the flush cycle, after the collection elements are dirty checked against the snapshot.

public abstract boolean isRowUpdatePossible ()

public abstract boolean isSnapshotEmpty (Serializable snapshot)

Is the snapshot empty?

public abstract boolean isUnreferenced ()

Is the collection unreferenced?

public abstract boolean isWrapper (Object collection)

Is this the wrapper for the given underlying collection instance?

public abstract boolean needsInserting (Object entry, int i, Type elemType)

Do we need to insert this element?

public abstract boolean needsRecreate (CollectionPersister persister)

Do we need to completely recreate this collection when it changes?

public abstract boolean needsUpdating (Object entry, int i, Type elemType)

Do we need to update this element?

public abstract void postAction ()

After flushing, clear any "queued" additions, since the database state is now synchronized with the memory state.

public abstract void preInsert (CollectionPersister persister)

Called before inserting rows, to ensure that any surrogate keys are fully generated

public abstract Iterator queuedAdditionIterator ()

Iterate the "queued" additions

public abstract Object readFrom (ResultSet rs, CollectionPersister role, CollectionAliases descriptor, Object owner)

Read a row from the JDBC result set

public abstract boolean setCurrentSession (SessionImplementor session)

Associate the collection with the given session.

Returns
  • false if the collection was already associated with the session
Throws
HibernateException if the collection was already associated with another open session

public abstract void setOwner (Object entity)

Set the reference to the owning entity

public abstract void setSnapshot (Serializable key, String role, Serializable snapshot)

After flushing, re-init snapshot state.

public abstract boolean unsetSession (SessionImplementor currentSession)

Disassociate this collection from the given session.

Returns
  • true if this was currently associated with the given session

public abstract boolean wasInitialized ()

Is this instance initialized?