Example usage for org.hibernate.collection.internal AbstractPersistentCollection getStoredSnapshot

List of usage examples for org.hibernate.collection.internal AbstractPersistentCollection getStoredSnapshot

Introduction

In this page you can find the example usage for org.hibernate.collection.internal AbstractPersistentCollection getStoredSnapshot.

Prototype

@Override
    public final Serializable getStoredSnapshot() 

Source Link

Usage

From source file:mojo.core.util.XHCollectionConverter.java

License:Open Source License

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
    logger.debug("### Hibernate collection");

    if (Hibernate.isInitialized(source)) {
        logger.debug("### Unwrapping value");
        AbstractPersistentCollection proxy = (AbstractPersistentCollection) source;
        Object collection = proxy.getStoredSnapshot();

        // Hibernate Set snapshots are HashMaps
        logger.debug("### Unwrapped value class: " + collection.getClass());

        if (proxy instanceof PersistentSortedSet) {
            collection = new TreeSet(((HashMap) collection).values());
        } else if (proxy instanceof PersistentSet) {
            collection = new HashSet(((HashMap) collection).values());
        }/* w w w . j ava 2s .c om*/

        context.convertAnother(collection);
    }
}