Q:

How do I stop hibernate returning multiple instances when using "join" fetch mode?

Given the following I am trying to force the child collection (countryData) to be loaded when I perform the query, this works however I end up with duplicates of the Bin records loaded.
public Collection<Bin> getBinsByPromotion(String season, String promotion) {
    final Session session = sessionFactory.getCurrentSession();
    try {
        session.beginTransaction();
        return (List<Bin>) session.createCriteria(Bin.class).
                setFetchMode("countryData", FetchMode.JOIN).
                add(Restrictions.eq("key.seasonCode", season)).
                add(Restrictions.eq("key.promotionCode", promotion)).
                add(Restrictions.ne("status", "closed")).
                list();
    } finally {
        session.getTransaction().commit();
    }
}

I don't want the default (lazy) behavior as the query will return ~8k records thus sending 16k additional queries off to get the child records.
If nothing else I'd prefer.
select ... from bins b where b.seasonCode = ?
                         and b.promotionCode = ?
                         and b.status <> 'Closed';
select ... from binCountry bc where bc.seasonCode = ?
                                and bc.promotionCode = ?;

A:

you can use CriteriaSpecification.DISTINCT_ROOT_ENTITY;
criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

