throw new UnexpectedException("During cascading save()", e);
}
}
private static void cascadeOrphans(JPABase base, PersistentCollection persistentCollection, boolean willBeSaved) {
SessionImpl session = ((SessionImpl) JPA.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) {
saveAndCascadeIfJPABase(o, willBeSaved);
}