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); }
/** Add an collection to the cache, with a given collection 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) } }