When using joins(outer join fetch or join fetch) in HQL or when using Criteria… you may end up having duplicate objects in your result list. The way is simple to filter the results. Simply use a HashSet or LinkedHashSet or TreeSet
Example:
List list = session.session.getNamedQuery(“My.Named.Query.With.Joins”).list();
// you might have duplicates now
Set set = new HashSet(list);
list.clear();
list.addAll(set);
// no duplicates now
You might use LinkedHashSet or TreeSet if you really care about the order of results, else cheers – BYE.
Filed under: Hibernate, Technical | 2 Comments
Tags: duplicate objects, duplicate results, hibernate, hql
Search
-
You are currently browsing the Sanchit Srivastava weblog archives.
Maybe this can help you:
query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
Thats certainly a better way. I didnt knew this way. Thanks for sharing across