Example usage for org.hibernate.persister.entity EntityPersister getPropertyTypes

List of usage examples for org.hibernate.persister.entity EntityPersister getPropertyTypes

Introduction

In this page you can find the example usage for org.hibernate.persister.entity EntityPersister getPropertyTypes.

Prototype

Type[] getPropertyTypes();

Source Link

Document

Get the Hibernate types of the class properties

Usage

From source file:com.hazelcast.hibernate.region.HazelcastCacheKeysFactory.java

License:Open Source License

@Override
public Object createNaturalIdKey(Object[] naturalIdValues, EntityPersister persister,
        SharedSessionContractImplementor session) {
    return new NaturalIdCacheKey(naturalIdValues, persister.getPropertyTypes(),
            persister.getNaturalIdentifierProperties(), persister.getRootEntityName(),
            (SessionImplementor) session);
}

From source file:com.miranteinfo.seam.hibernate.HibernateCascade.java

License:Open Source License

/**
 * Cascade an action from the parent entity instance to all its children.  This
 * form is typicaly called from within cascade actions.
 *
 * @param persister The parent's entity persister
 * @param parent The parent reference.//from   ww  w.ja v  a2 s .  c  om
 * @param anything Anything ;)   Typically some form of cascade-local cache
 * which is specific to each CascadingAction type
 * @throws HibernateException
 */
public void cascade(final EntityPersister persister, final Object parent, final Object anything)
        throws HibernateException {

    if (persister.hasCascades() || action.requiresNoCascadeChecking()) { // performance opt
        if (log.isTraceEnabled()) {
            log.trace("processing cascade " + action + " for: " + persister.getEntityName());
        }

        Type[] types = persister.getPropertyTypes();
        CascadeStyle[] cascadeStyles = persister.getPropertyCascadeStyles();
        EntityMode entityMode = eventSource.getEntityMode();
        boolean hasUninitializedLazyProperties = persister.hasUninitializedLazyProperties(parent, entityMode);
        for (int i = 0; i < types.length; i++) {
            CascadeStyle style = cascadeStyles[i];
            if (hasUninitializedLazyProperties && persister.getPropertyLaziness()[i]
                    && !action.performOnLazyProperty()) {
                //do nothing to avoid a lazy property initialization
                continue;
            }

            if (style.doCascade(action)) {
                cascadeProperty(persister.getPropertyValue(parent, i, entityMode), types[i], style, anything,
                        false);
            } else if (action.requiresNoCascadeChecking()) {
                action.noCascade(eventSource, persister.getPropertyValue(parent, i, entityMode), parent,
                        persister, i);
            }
        }

        if (log.isTraceEnabled()) {
            log.trace("done processing cascade " + action + " for: " + persister.getEntityName());
        }
    }
}

From source file:corner.orm.hibernate.expression.NewExpressionExample.java

License:Apache License

public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {

    EntityPersister meta = criteriaQuery.getFactory().getEntityPersister(criteriaQuery.getEntityName(criteria));
    String[] propertyNames = meta.getPropertyNames();
    Type[] propertyTypes = meta.getPropertyTypes();
    //TODO: get all properties, not just the fetched ones!
    Object[] values = meta.getPropertyValues(entity, getEntityMode(criteria, criteriaQuery));
    List<TypedValue> list = new ArrayList<TypedValue>();
    for (int i = 0; i < propertyNames.length; i++) {
        Object value = values[i];
        Type type = propertyTypes[i];
        String name = propertyNames[i];

        boolean isPropertyIncluded = i != meta.getVersionProperty() && isPropertyIncluded(value, name, type);

        if (isPropertyIncluded) {
            if (propertyTypes[i].isComponentType()) {
                addComponentTypedValues(name, value, (AbstractComponentType) type, list, criteria,
                        criteriaQuery);/*  ww w.  jav a2s.c  om*/
            } else {
                addPropertyTypedValue(name, value, type, list);
            }
        }
    }
    return (TypedValue[]) list.toArray(TYPED_VALUES);
}

From source file:ome.tools.hibernate.HibernateUtils.java

License:Open Source License

/**
 * loads collections which have been filtered or nulled by the user
 * /* w ww .  ja v a 2 s .  c  o  m*/
 * @param entity
 *            IObject to have its collections reloaded
 * @param id
 *            persistent (db) id of this entity
 * @param currentState
 *            the possibly changed field data for this entity
 * @param previousState
 *            the field data as seen in the db
 * @param propertyNames
 *            field names
 * @param types
 *            Hibernate {@link Type} for each field
 * @param detailsIndex
 *            the index of the {@link Details} instance (perf opt)
 */
public static void fixNulledOrFilteredCollections(IObject entity, IObject target, EntityPersister persister,
        SessionImplementor source) {

    Object[] currentState = persister.getPropertyValues(entity, source.getEntityMode());
    Object[] previousState = persister.getPropertyValues(target, source.getEntityMode());
    String[] propertyNames = persister.getPropertyNames();
    Type[] types = persister.getPropertyTypes();

    int detailsIndex = detailsIndex(propertyNames);
    Details d = (Details) currentState[detailsIndex];
    if (d != null) {
        Set<String> s = d.filteredSet();
        for (String string : s) {
            string = LsidUtils.parseField(string);
            int idx = index(string, propertyNames);
            Object previous = previousState[idx];
            if (!(previous instanceof Collection)) // implies
            // not null
            {
                throw new InternalException(String.format(
                        "Invalid collection found for filtered " + "field %s in previous state for %s", string,
                        entity));
            }
            log("Copying filtered collection ", string);
            Collection copy = copy(((Collection) previous));
            persister.setPropertyValue(entity, idx, copy, source.getEntityMode());
        }
    }

    for (int i = 0; i < types.length; i++) {
        Type t = types[i];
        if (t.isCollectionType() && null == currentState[i]) {
            Object previous = previousState[i];
            if (previous == null) {
                // ignore. If the system gave it to us, it can handle it.
            } else if (previous instanceof Collection) {
                if (!Hibernate.isInitialized(previous)) {
                    log("Skipping uninitialized collection: ", propertyNames[i]);
                    persister.setPropertyValue(entity, i, previous, source.getEntityMode());
                } else {
                    log("Copying nulled collection: ", propertyNames[i]);
                    Collection copy = copy(((Collection) previous));
                    persister.setPropertyValue(entity, i, copy, source.getEntityMode());
                }
            } else if (previous instanceof Map) {
                if (!Hibernate.isInitialized(previous)) {
                    log("Skipping uninitialized map: ", propertyNames[i]);
                    persister.setPropertyValue(entity, i, previous, source.getEntityMode());
                } else {
                    Map copy = copy((Map) previous);
                    persister.setPropertyValue(entity, i, copy, source.getEntityMode());
                }
            } else {
                throw new InternalException(String.format(
                        "Invalid collection found for null " + "field %s in previous state for %s",
                        propertyNames[i], entity));
            }
        }
    }
}

From source file:org.babyfish.hibernate.persister.UncompletedInitializedProperties.java

License:Open Source License

static void update(EntityPersisterBridge entityPersisterBridge, Object[] state, Object entity, Serializable id,
        Object rowId, SessionImplementor session) {
    FieldInterceptor fieldInterceptor = FieldInterceptionHelper.extractFieldInterceptor(entity);
    if (!(fieldInterceptor instanceof HibernateObjectModelScalarLoader)) {
        return;//from  w ww  . j a v  a  2  s  . co m
    }
    HibernateObjectModelScalarLoader hibernateObjectModelScalarLoader = (HibernateObjectModelScalarLoader) fieldInterceptor;
    if (!hibernateObjectModelScalarLoader.isIncompletelyInitialized()) {
        return;
    }
    ObjectModel objectModel = hibernateObjectModelScalarLoader.getObjectModel();
    JPAObjectModelMetadata objectModelMetadata = objectModel.getObjectModelMetadata();
    EntityPersister entityPersister = entityPersisterBridge.getEntityPersister();
    String[] names = entityPersister.getPropertyNames();
    Type[] types = entityPersister.getPropertyTypes();
    boolean[] updateabilities = entityPersister.getPropertyUpdateability();

    List<Integer> updatePropertyIndexList = new ArrayList<>();
    for (int propertyIndex = 0; propertyIndex < names.length; propertyIndex++) {
        if (updateabilities[propertyIndex]) {
            Property property = objectModelMetadata.getMappingSources().get(names[propertyIndex]);
            if (property instanceof ScalarProperty) {
                ScalarProperty scalarProperty = (ScalarProperty) property;
                if (scalarProperty.isDeferrable()) {
                    int propertyId = scalarProperty.getId();
                    if (!objectModel.isDisabled(propertyId) && !objectModel.isUnloaded(propertyId)) {
                        updatePropertyIndexList.add(propertyIndex);
                    }
                }
            }
        }
    }
    if (updatePropertyIndexList.isEmpty()) {
        return;
    }
    int[] updatePropertyIndexes = new int[updatePropertyIndexList.size()];
    for (int i = updatePropertyIndexList.size() - 1; i >= 0; i--) {
        updatePropertyIndexes[i] = updatePropertyIndexList.get(i);
    }

    boolean[] tableUpdateNeeded = entityPersisterBridge.getTableUpdateNeeded(updatePropertyIndexes);
    boolean[][] propertyColumnUpdateable = entityPersisterBridge.getPropertyColumnUpdateable();
    for (int tableIndex = 0; tableIndex < entityPersisterBridge.getTableSpan(); tableIndex++) {
        if (tableUpdateNeeded[tableIndex]) {
            StringBuilder builder = new StringBuilder();
            builder.append("update ").append(entityPersisterBridge.getTableName(tableIndex)).append(" set ");
            boolean addComma = false;
            for (int propertyIndex : updatePropertyIndexes) {
                if (entityPersisterBridge.isPropertyOfTable(propertyIndex, tableIndex)) {
                    String[] columnNames = entityPersisterBridge.getPropertyColumnNames(propertyIndex);
                    for (int columnIndex = 0; columnIndex < columnNames.length; columnIndex++) {
                        if (propertyColumnUpdateable[propertyIndex][columnIndex]) {
                            if (addComma) {
                                builder.append(", ");
                            } else {
                                addComma = true;
                            }
                            builder.append(columnNames[columnIndex]).append(" = ?");
                        }
                    }
                }
            }
            if (!addComma) {
                continue;
            }
            builder.append(" where ");
            addComma = false;
            if (tableIndex == 0 && rowId != null) {
                builder.append(entityPersisterBridge.getRowIdName()).append(" = ?");
            } else {
                for (String keyColumn : entityPersisterBridge.getKeyColumns(tableIndex)) {
                    if (addComma) {
                        builder.append(", ");
                    } else {
                        addComma = true;
                    }
                    builder.append(keyColumn).append(" = ?");
                }
            }
            String sql = builder.toString();
            JdbcCoordinator jdbcCoordinator = session.getTransactionCoordinator().getJdbcCoordinator();
            PreparedStatement preparedStatement = jdbcCoordinator.getStatementPreparer().prepareStatement(sql);
            try {
                int paramIndex = 1;
                for (int propertyIndex : updatePropertyIndexes) {
                    if (entityPersisterBridge.isPropertyOfTable(propertyIndex, tableIndex)) {
                        types[propertyIndex].nullSafeSet(preparedStatement, state[propertyIndex], paramIndex,
                                propertyColumnUpdateable[propertyIndex], session);
                        paramIndex += ArrayHelper.countTrue(propertyColumnUpdateable[propertyIndex]);
                    }
                }
                if (tableIndex == 0 && rowId != null) {
                    preparedStatement.setObject(paramIndex, rowId);
                } else {
                    entityPersister.getIdentifierType().nullSafeSet(preparedStatement,
                            id != null ? id
                                    : objectModel.getScalar(objectModelMetadata.getEntityIdProperty().getId()),
                            paramIndex, session);
                }
                preparedStatement.executeUpdate();
            } catch (SQLException ex) {
                throw new HibernateException(ex);
            } finally {
                jdbcCoordinator.release(preparedStatement);
            }
        }
    }
}

From source file:org.codehaus.groovy.grails.orm.hibernate.support.ClosureEventTriggeringInterceptor.java

License:Apache License

@Override
protected Serializable performSaveOrReplicate(Object entity, EntityKey key, EntityPersister persister,
        boolean useIdentityColumn, Object anything, EventSource source, boolean requiresImmediateIdAccess) {
    validate(entity, persister, source);

    Serializable id = key == null ? null : key.getIdentifier();

    boolean inTxn = source.getJDBCContext().isTransactionInProgress();
    boolean shouldDelayIdentityInserts = !inTxn && !requiresImmediateIdAccess;

    // Put a placeholder in entries, so we don't recurse back and try to save() the
    // same object again. QUESTION: should this be done before onSave() is called?
    // likewise, should it be done before onUpdate()?
    source.getPersistenceContext().addEntry(entity, Status.SAVING, null, null, id, null, LockMode.WRITE,
            useIdentityColumn, persister, false, false);

    cascadeBeforeSave(source, persister, entity, anything);

    if (useIdentityColumn && !shouldDelayIdentityInserts) {
        log.trace("executing insertions");
        source.getActionQueue().executeInserts();
    }/*from w w w  .  j  a  va2  s  . co  m*/

    Object[] values = persister.getPropertyValuesToInsert(entity, getMergeMap(anything), source);
    Type[] types = persister.getPropertyTypes();

    boolean substitute = substituteValuesIfNecessary(entity, id, values, persister, source);

    if (persister.hasCollections()) {
        substitute = substitute || visitCollectionsBeforeSave(entity, id, values, types, source);
    }

    if (substitute) {
        persister.setPropertyValues(entity, values, source.getEntityMode());
    }

    TypeHelper.deepCopy(values, types, persister.getPropertyUpdateability(), values, source);

    new ForeignKeys.Nullifier(entity, false, useIdentityColumn, source).nullifyTransientReferences(values,
            types);
    new Nullability(source).checkNullability(values, persister, false);

    if (useIdentityColumn) {
        EntityIdentityInsertAction insert = new EntityIdentityInsertAction(values, entity, persister, source,
                shouldDelayIdentityInserts);
        if (!shouldDelayIdentityInserts) {
            log.debug("executing identity-insert immediately");
            source.getActionQueue().execute(insert);
            id = insert.getGeneratedId();
            if (id != null) {
                // As of HHH-3904, if the id is null the operation was vetoed so we bail
                key = new EntityKey(id, persister, source.getEntityMode());
                source.getPersistenceContext().checkUniqueness(key, entity);
            }
        } else {
            log.debug("delaying identity-insert due to no transaction in progress");
            source.getActionQueue().addAction(insert);
            key = insert.getDelayedEntityKey();
        }
    }

    if (key != null) {
        Object version = Versioning.getVersion(values, persister);
        source.getPersistenceContext().addEntity(entity,
                (persister.isMutable() ? Status.MANAGED : Status.READ_ONLY), values, key, version,
                LockMode.WRITE, useIdentityColumn, persister, isVersionIncrementDisabled(), false);
        //source.getPersistenceContext().removeNonExist(new EntityKey(id, persister, source.getEntityMode()));

        if (!useIdentityColumn) {
            source.getActionQueue()
                    .addAction(new EntityInsertAction(id, values, entity, version, persister, source));
        }

        cascadeAfterSave(source, persister, entity, anything);
        // Very unfortunate code, but markInterceptorDirty is private. Once HHH-3904 is resolved remove this overridden method!
        if (markInterceptorDirtyMethod != null) {
            ReflectionUtils.invokeMethod(markInterceptorDirtyMethod, this, entity, persister, source);
        }
    }

    return id;
}

From source file:org.compass.gps.device.hibernate.lifecycle.HibernateEventListenerUtils.java

License:Apache License

public static Collection getUnpersistedCascades(CompassGpsInterfaceDevice compassGps, Object entity,
        SessionFactoryImplementor sessionFactory, Cascade cascade, Collection visited) {
    if (visited.contains(entity)) {
        return Collections.EMPTY_SET;
    }//  w w w  .ja v  a 2  s .c  om
    visited.add(entity);

    ClassMetadata classMetadata = sessionFactory.getClassMetadata(entity.getClass());
    if (classMetadata == null) {
        for (Iterator iter = sessionFactory.getAllClassMetadata().values().iterator(); iter.hasNext();) {
            ClassMetadata temp = (ClassMetadata) iter.next();
            if (entity.getClass().equals(temp.getMappedClass(EntityMode.POJO))) {
                classMetadata = temp;
                break;
            }
        }
    }
    Assert.notNull(classMetadata, "Failed to lookup Hibernate ClassMetadata for entity [" + entity + "]");
    String entityName = classMetadata.getEntityName();
    EntityPersister persister = sessionFactory.getEntityPersister(entityName);

    CompassMapping compassMapping = ((InternalCompass) compassGps.getIndexCompass()).getMapping();
    ClassMapping classMapping = (ClassMapping) compassMapping.getMappingByClass(entity.getClass());
    if (classMapping == null) {
        return Collections.EMPTY_SET;
    }

    //        CascadeStyle[] cascadeStyles = persister.getEntityMetamodel().getCascadeStyles();
    String[] propertyNames = persister.getPropertyNames();
    Type[] types = persister.getPropertyTypes();
    Set dependencies = new HashSet();
    for (int i = 0, len = propertyNames.length; i < len; i++) {
        // property cascade includes save/update?
        //            CascadeStyle cascadeStyle = cascadeStyles[i];
        //            if (!cascadeStyle.doCascade(CascadingAction.SAVE_UPDATE)) {
        //                continue;
        //            }
        // property is mapped in Compass?
        String name = propertyNames[i];
        Mapping mapping = classMapping.getMapping(name);
        if (mapping == null) {
            continue;
        }
        // property value is not null?
        Object propertyValue = persister.getPropertyValue(entity, name, EntityMode.POJO);
        if (propertyValue == null) {
            continue;
        }
        // find actual property type
        // todo may not be correct see http://www.hibernate.org/hib_docs/v3/api/org/hibernate/type/EntityType.html#getReturnedClass()
        // todo may need to use class name string comparison instead
        Class propertyType;
        Type type = types[i];
        boolean collection = false;
        if (type instanceof CollectionType) {
            CollectionType collectionType = (CollectionType) type;
            propertyType = persister.getFactory().getCollectionPersister(collectionType.getRole())
                    .getElementType().getReturnedClass();
            collection = true;
        } else {
            propertyType = type.getReturnedClass();
        }
        // Mirroring is cascaded for this property?
        if (!compassGps.hasMappingForEntityForMirror(propertyType, cascade)) {
            continue;
        }
        // find dependent unpersisted property value(s)
        ResourceMapping propertyTypeMapping = compassMapping.getMappingByClass(propertyType);
        Mapping[] idMappings = propertyTypeMapping.getIdMappings();
        for (int j = 0, jlen = idMappings.length; j < jlen; j++) {
            ClassPropertyMetaDataMapping idMapping = (ClassPropertyMetaDataMapping) idMappings[j];
            try {
                // initiaize the value in case it is lazy (and only for the first time)
                if (j == 0) {
                    if (propertyValue instanceof HibernateProxy) {
                        propertyValue = ((HibernateProxy) propertyValue).getHibernateLazyInitializer()
                                .getImplementation();
                    }
                }
                if (collection) {
                    for (Iterator iter = ((Collection) propertyValue).iterator(); iter.hasNext();) {
                        Object obj = iter.next();
                        Object id = idMapping.getGetter().get(obj);
                        if (id == null) {
                            dependencies.add(obj);
                        }
                        dependencies.addAll(
                                getUnpersistedCascades(compassGps, obj, sessionFactory, cascade, visited));
                    }
                } else {
                    Object id = idMapping.getGetter().get(propertyValue);
                    if (id == null) {
                        dependencies.add(propertyValue);
                    }
                    dependencies.addAll(getUnpersistedCascades(compassGps, propertyValue, sessionFactory,
                            cascade, visited));
                }
            } catch (Exception e) {
                // ignore
            }
        }
    }
    return dependencies;
}

From source file:org.seasar.hibernate.jpa.metadata.HibernateAttributeDesc.java

License:Apache License

/**
 * <code>value</code>????<code>allValues</code>?????
 * //ww w  .j a  v a2 s .c  o  m
 * @param allValues
 *            ??
 * @param type
 *            Hibernate?
 * @param value
 *            ????????
 */
protected void gatherAttributeValues(final List<Object> allValues, final Type type, final Object value) {

    if (value == null) {
        allValues.add(null);
        return;
    }
    if (!isReadTargetType(type)) {
        return;
    }

    if (type.isEntityType()) {
        final EntityType entityType = EntityType.class.cast(type);

        if (entityType.isReferenceToPrimaryKey()) {
            gatherIdAttributeValues(allValues, entityType, value);
        } else {
            final String name = entityType.getAssociatedEntityName();
            final EntityPersister ep = factory.getEntityPersister(name);
            final Type[] subtypes = ep.getPropertyTypes();
            final Object[] subvalue = ep.getPropertyValues(value, EntityMode.POJO);
            for (int i = 0; i < subtypes.length; i++) {
                gatherAttributeValues(allValues, subtypes[i], subvalue[i]);
            }
        }

    } else if (type.isComponentType()) {
        final AbstractComponentType componentType = AbstractComponentType.class.cast(type);
        final Object[] subvalues = componentType.getPropertyValues(value, EntityMode.POJO);
        final Type[] subtypes = componentType.getSubtypes();
        for (int i = 0; i < subtypes.length; i++) {
            gatherAttributeValues(allValues, subtypes[i], subvalues[i]);
        }

    } else {
        allValues.add(convert(type, value));
    }
}

From source file:owldb.util.OWLDBEventListener.java

License:Open Source License

/**
 * Reassociate an Object to the Session provided.
 * //from w w w .j  av  a 2 s  .c o  m
 * @param source The session implementor source
 * @param object Worked object
 * @param result The loaded object
 * @param status The Hibernate status
 */
private void reassociateObject(final SessionImplementor source, final Object object, final Object result,
        final Status status) {
    final Serializable id = result instanceof OWLObject ? this.getID(source, (OWLObject) result)
            : source.getContextEntityIdentifier(result);
    if (id == null)
        return;

    final EntityPersister persister = source.getEntityPersister(null, object);
    final EntityMode entityMode = source.getEntityMode();
    final EntityKey key = new EntityKey(id, persister, entityMode);

    // Get a snapshot
    final Type[] types = persister.getPropertyTypes();
    final Object[] resultValues = persister.getPropertyValues(result, entityMode);
    final Object[] values = persister.getPropertyValues(object, entityMode);

    if (persister.hasCollections()) {
        for (int i = 0; i < types.length; i++) {
            if (!types[i].isCollectionType())
                continue;

            if (values[i] instanceof Collection<?>) {
                final Collection<?> unsavedCol = (Collection<?>) values[i];
                final CollectionType collectionType = (CollectionType) types[i];
                final CollectionPersister colPersister = source.getFactory()
                        .getCollectionPersister(collectionType.getRole());
                final PersistenceContext persistenceContext = source.getPersistenceContext();
                final PersistentCollection persistentCollection = collectionType.wrap(source, unsavedCol);
                final PersistentCollection resultCol = (PersistentCollection) resultValues[i];
                final Serializable currentKey = resultCol.getKey();
                persistenceContext.addInitializedCollection(colPersister, persistentCollection, currentKey);
                values[i] = persistentCollection;
            }

            persister.setPropertyValues(object, values, entityMode);
        }
    }

    TypeHelper.deepCopy(values, types, persister.getPropertyUpdateability(), values, source);
    final Object version = Versioning.getVersion(values, persister);

    // lazyPropertiesAreUnfetched: Will be ignored, using the existing Entry
    // instead
    source.getPersistenceContext().addEntity(object, status, values, key, version, LockMode.NONE, true,
            persister, false, true);
    persister.afterReassociate(object, source);
}

From source file:owldb.util.OWLDBEventListener.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from  w w w  . j a  va2 s .  c o  m*/
public void onPostDelete(final PostDeleteEvent event) {
    final SessionImplementor source = event.getSession();
    final EntityPersister per = event.getPersister();
    final Session session = source.getFactory().openSession();
    Transaction t = null;
    try {
        t = session.beginTransaction();
        final Object deletedObject = event.getEntity();
        if (deletedObject instanceof OWLObject) {
            final Type[] types = per.getPropertyTypes();
            final String[] names = per.getPropertyNames();

            for (int i = 0; i < names.length; i++) {
                if (types[i] instanceof ManyToOneType) {
                    final Object value = per.getPropertyValue(deletedObject, names[i], EntityMode.POJO);
                    this.deleteReference(session, source, value);
                } else if (types[i] instanceof CollectionType) {
                    final Object values = per.getPropertyValue(deletedObject, names[i], EntityMode.POJO);
                    if (values instanceof PersistentCollection) {
                        final PersistentCollection pc = (PersistentCollection) values;
                        pc.forceInitialization();
                        for (final Object value : (Collection<?>) values)
                            this.deleteReference(session, source, value);
                    }
                }
            }
        }
        t.commit();
    } catch (final RuntimeException ex) {
        if (t != null)
            t.rollback();
        throw ex;
    } finally {
        session.close();
    }
}