Reputation: 1260
Here is my table structure in mysql having Entity Name Extension
.
I want to get all the unique extcat
in my result set using hibernate 4.1
.
Like extcat(image, word)
.
How to get this.
| extid | extName | extcat
---------------------------
1 | jpg | image
2 | jpg | image
3 | doc | word
4 | dcx | word
Upvotes: 2
Views: 228
Reputation: 2254
Using Criteria:-
Criteria cr = getCurrentSession().createCritiera(Extension.class)
.setProjection(Projections.projectionList()
.add(Projections.distinct(Projections.property("extcat")))
.add(Projections.property("extid"), "extid")
.add(Projections.property("extName"), "extName"))
.setResultTransformer(Transformers.aliasToBean(Extension.class));
List<Extension> list = cr.list();
Upvotes: 1
Reputation: 358
Make use of Criteria feature in Hibernate for getting the unique resultsets.
Upvotes: 0