/** * Delete any entities that were removed from the collection */ private static void deleteOrphans(EventSource eventSource, String entityName, PersistentCollection pc) throws HibernateException { //TODO: suck this logic into the collection! final Collection orphans; if ( pc.wasInitialized() ) { final CollectionEntry ce = eventSource.getPersistenceContext().getCollectionEntry( pc ); orphans = ce==null ? java.util.Collections.EMPTY_LIST : ce.getOrphans( entityName, pc ); } else { orphans = pc.getQueuedOrphans( entityName ); } for ( Object orphan : orphans ) { if ( orphan != null ) { LOG.tracev( "Deleting orphaned entity instance: {0}", entityName ); eventSource.delete( entityName, orphan, false, new HashSet() ); } } } }
/** * Delete any entities that were removed from the collection */ private void deleteOrphans(String entityName, PersistentCollection pc) throws HibernateException { //TODO: suck this logic into the collection! final Collection orphans; if ( pc.wasInitialized() ) { CollectionEntry ce = eventSource.getPersistenceContext().getCollectionEntry(pc); orphans = ce==null ? CollectionHelper.EMPTY_COLLECTION : ce.getOrphans(entityName, pc); } else { orphans = pc.getQueuedOrphans(entityName); } final Iterator orphanIter = orphans.iterator(); while ( orphanIter.hasNext() ) { Object orphan = orphanIter.next(); if (orphan!=null) { LOG.tracev( "Deleting orphaned entity instance: {0}", entityName ); eventSource.delete( entityName, orphan, false, new HashSet() ); } } } }
/** * Delete any entities that were removed from the collection */ private void deleteOrphans(String entityName, PersistentCollection pc) throws HibernateException { //TODO: suck this logic into the collection! final Collection orphans; if ( pc.wasInitialized() ) { CollectionEntry ce = eventSource.getPersistenceContext().getCollectionEntry(pc); orphans = ce==null ? CollectionHelper.EMPTY_COLLECTION : ce.getOrphans(entityName, pc); } else { orphans = pc.getQueuedOrphans(entityName); } final Iterator orphanIter = orphans.iterator(); while ( orphanIter.hasNext() ) { Object orphan = orphanIter.next(); if (orphan!=null) { LOG.tracev( "Deleting orphaned entity instance: {0}", entityName ); eventSource.delete( entityName, orphan, false, new HashSet() ); } } } }
/** * Delete any entities that were removed from the collection */ private static void deleteOrphans(EventSource eventSource, String entityName, PersistentCollection pc) throws HibernateException { //TODO: suck this logic into the collection! final Collection orphans; if ( pc.wasInitialized() ) { final CollectionEntry ce = eventSource.getPersistenceContext().getCollectionEntry( pc ); orphans = ce==null ? java.util.Collections.EMPTY_LIST : ce.getOrphans( entityName, pc ); } else { orphans = pc.getQueuedOrphans( entityName ); } for ( Object orphan : orphans ) { if ( orphan != null ) { LOG.tracev( "Deleting orphaned entity instance: {0}", entityName ); eventSource.delete( entityName, orphan, false, new HashSet() ); } } } }
private void cascadeOrphans(JPABase base, PersistentCollection persistentCollection, boolean willBeSaved) { String dbName = JPA.getDBName(this.getClass()); SessionImpl session = ((SessionImpl) JPA.em(dbName).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) { saveAndCascadeIfJPABase(o, willBeSaved); } } } } } }