Skip to content

Commit

Permalink
HSEARCH-1260 Simplify HibernateSessionLoadingInitializer as we don't …
Browse files Browse the repository at this point in the history
…have to deal with detached collections anymore
  • Loading branch information
Sanne committed Jan 23, 2014
1 parent 0eff03b commit 8bc0e23
Showing 1 changed file with 2 additions and 17 deletions.
Expand Up @@ -22,9 +22,7 @@
import java.util.Collection;
import java.util.Map;

import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.hibernate.search.spi.InstanceInitializer;
Expand Down Expand Up @@ -64,27 +62,14 @@ public Object unproxy(Object instance) {

@Override
public <T> Collection<T> initializeCollection(Collection<T> value) {
if ( value instanceof PersistentCollection ) {
preparePersistentCollection( (PersistentCollection) value );
}
//No action needed
return value;
}

@Override
public <K,V> Map<K,V> initializeMap(Map<K,V> value) {
if ( value instanceof PersistentCollection ) {
preparePersistentCollection( (PersistentCollection) value );
}
//No action needed
return value;
}

private void preparePersistentCollection( PersistentCollection value ) {
// we have to check that it's not already associated, might have happened via cascading:
if ( value.setCurrentSession( hibernateSession ) ) {
String role = value.getRole();
CollectionPersister collectionPersister = hibernateSession.getFactory().getCollectionPersister( role );
hibernateSession.getPersistenceContext().addInitializedDetachedCollection( collectionPersister, value );
}
}

}

0 comments on commit 8bc0e23

Please sign in to comment.