Naveen Prakash
Naveen Prakash

Reputation: 41

How to apply DISTINCT for Child Object using hibernate criteria

I have object called 'MasterObj'. In that 'MasterObj', I have a child object called 'EmployeeObj'(foreign Key)

The relation ship between 'MasterObj' and 'EmployeeObj' is one to Many.

And my 'MasterObj' had so many duplicate 'employeeObj'

I need a count of MasterObj with DISTINCT or without duplication of emp_SlNo

How can I filter the duplicate emp_SlNo from my MasterObj using hibernate criteria.

Sorry for the my bad english.

Thanks in adance.

Upvotes: 1

Views: 677

Answers (1)

Naveen Prakash
Naveen Prakash

Reputation: 41

After so much of google, finally I got this code:

ProjectionList projList = Projections.projectionList();
projList.add(Projections.property("id.state"));
projList.add(Projections.property("id.uspsCity"));
criteria.setProjection(Projections.distinct(projList));

And it works fine for me. It eliminates the duplicate child object from parent objects.

Upvotes: 2

Related Questions