package de.terrestris.shogun2.dao;

import java.util.HashSet;
import java.util.Set;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import de.terrestris.shogun2.model.layer.Layer;
import de.terrestris.shogun2.model.module.Map;

@Repository("mapDao")
public class MapDao<E extends Map> extends
		ModuleDao<E> {

	/**
	 * Public default constructor for this DAO.
	 */
	@SuppressWarnings("unchecked")
	public MapDao() {
		super((Class<E>) Map.class);
	}

	/**
	 * Constructor that has to be called by subclasses.
	 *
	 * @param clazz
	 */
	protected MapDao(Class<E> clazz) {
		super(clazz);
	}

	/**
	 *
	 */
	@SuppressWarnings("unchecked")
	public Set<E> findMapsWithLayer(Layer layer) throws HibernateException {
		Criteria criteria = createDistinctRootEntityCriteria();

		criteria.createAlias("mapLayers", "ml");
		criteria.add(Restrictions.eq("ml.id", layer.getId()));

		return new HashSet<E>(criteria.list());
	}

}

@@ -76,44 +76,36 @@
 til.
-Se
+Lis
 t;%0A
-%0A
 import 
-org.hibernate.Criteria;
+java.util.Set;%0A
 %0Aimp
@@ -146,53 +146,8 @@
 on;%0A
-import org.hibernate.criterion.Restrictions;%0A
 impo
@@ -671,40 +671,8 @@
  */%0A
-%09@SuppressWarnings(%22unchecked%22)%0A
 %09pub
@@ -747,166 +747,93 @@
 %7B%0A%09%09
-Criteria criteria = createDistinctRootEntityCriteria();%0A%0A%09%09criteria.createAlias(%22mapLayers%22, %22ml%22);%0A%09%09criteria.add(Restrictions.eq(%22ml.id%22, layer.getId())
+final List%3CE%3E resultList = this.findAllWithCollectionContaining(%22mapLayers%22, layer
 );%0A
-%0A
 %09%09re
@@ -853,26 +853,20 @@
 Set%3C
-E
 %3E(
-criteria.l
+resultL
 ist
-()
 );%0A%09

Make use of findAllWithCollectionContaining()