AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



java-hibernate: Use Distinct query in Hql?

could you plz explain the above concept with example.

java x 210
hibernate x 23
Posted On : 2016-08-19 06:59:25.0
profile MOHAMMAD SALEEM BASHA - anyforum.in MOHAMMAD SALEEM BASHA
266150
up-rate
3
down-rate

Answers


Use Projections.distinct to select distinct elements from a class.

criteria.setProjection(Projections.distinct(Projections.property("id")));

Note:
----------------------
instead of getting a list of objects, you will now get a list of ids. If you want to get the list of object use

criteria.setProjection(
Projections.distinct(
Projections.projectionList()
.add(Projections.id())
.add(Projections.property("the property that you want to ordered by"))
)
);

Posted On : 2016-08-19 22:53:39
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523185319357
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in