Java Code Examples for org.hibernate.collection.PersistentCollection#unsetSession()

The following examples show how to use org.hibernate.collection.PersistentCollection#unsetSession() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatefulPersistenceContext.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Add an collection to the cache, with a given collection entry.
 *
 * @param coll The collection for which we are adding an entry.
 * @param entry The entry representing the collection.
 * @param key The key of the collection's entry.
 */
private void addCollection(PersistentCollection coll, CollectionEntry entry, Serializable key) {
	collectionEntries.put( coll, entry );
	CollectionKey collectionKey = new CollectionKey( entry.getLoadedPersister(), key, session.getEntityMode() );
	PersistentCollection old = ( PersistentCollection ) collectionsByKey.put( collectionKey, coll );
	if ( old != null ) {
		if ( old == coll ) {
			throw new AssertionFailure("bug adding collection twice");
		}
		// or should it actually throw an exception?
		old.unsetSession( session );
		collectionEntries.remove( old );
		// watch out for a case where old is still referenced
		// somewhere in the object graph! (which is a user error)
	}
}
 
Example 2
Source File: EvictVisitor.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void evictCollection(Object value, CollectionType type) {

		final Object pc;
		if ( type.hasHolder( getSession().getEntityMode() ) ) {
			pc = getSession().getPersistenceContext().removeCollectionHolder(value);
		}
		else if ( value instanceof PersistentCollection ) {
			pc = value;
		}
		else {
			return; //EARLY EXIT!
		}

		PersistentCollection collection = (PersistentCollection) pc;
		if ( collection.unsetSession( getSession() ) ) evictCollection(collection);
	}