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:
[plain]
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
[/plain]

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..

Leave a Reply