Hibernate Criteria Duplicate Records Issue [Solved]

Hibernate Criteria Duplicate Records Issue:
Problem:
Duplicate same records with hibernate join.

In Hibernate if we did join, we may get duplicates sometime.

Below are the possible ways to resolve the duplicate same record value issue,

Possible Solutions:
1. criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
2. criteria.setProjection(Projections.distinct(Projections.property(“id”)));
3. criteria.setProjection(Projections.distinct(Projections.id()));

Recommended Solution:

criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

If nothing is working then change the list to set, so that duplicates will be avoided from java side.

Hibernate Recommended Books:

Feel free to post your comments/feedbacks..

214 total views, 3 views today

Leave a Reply

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