Example usage for org.hibernate.engine.spi CollectionEntry getOrphans

List of usage examples for org.hibernate.engine.spi CollectionEntry getOrphans

Introduction

In this page you can find the example usage for org.hibernate.engine.spi CollectionEntry getOrphans.

Prototype

public Collection getOrphans(String entityName, PersistentCollection collection) throws HibernateException 

Source Link

Document

Get the collection orphans (entities which were removed from the collection)

Usage

From source file:br.gov.jfrj.siga.model.Objeto.java

License:Open Source License

private static void cascadeOrphans(Objeto base, PersistentCollection persistentCollection, boolean willBeSaved)
        throws UnexpectedException {
    SessionImpl session = ((SessionImpl) em().getDelegate());
    PersistenceContext pc = session.getPersistenceContext();
    CollectionEntry ce = pc.getCollectionEntry(persistentCollection);

    if (ce != null) {
        CollectionPersister cp = ce.getLoadedPersister();
        if (cp != null) {
            Type ct = cp.getElementType();
            if (ct instanceof EntityType) {
                EntityEntry entry = pc.getEntry(base);
                String entityName = entry.getEntityName();
                entityName = ((EntityType) ct).getAssociatedEntityName(session.getFactory());
                if (ce.getSnapshot() != null) {
                    Collection orphans = ce.getOrphans(entityName, persistentCollection);
                    for (Object o : orphans) {
                        saveAndCascadeIfObjeto(o, willBeSaved);
                    }// ww w .j a v a  2 s  .com
                }
            }
        }
    }
}