Hibernate get distinct list with Criteria

The only way I could figure out to get the distinct list using Hibernate Criteria is by using ResultTransformer function.

eg.

List result = session.createCriteria(Order.class)
        .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
        -------
        .list();

The con is it fetches all the objects and then filters it. (very time consuming)

The only way to circumvent this problem is to write query using HQL.

If you find a way to do that efficiently using Criteria, let me know 🙂

One Reply to “Hibernate get distinct list with Criteria”

  1. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you. Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.