Zahid Khan
Zahid Khan

Reputation: 1260

How to get the unique result sets using hibernate 4.1

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

Answers (2)

karim mohsen
karim mohsen

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

arjun99
arjun99

Reputation: 358

Make use of Criteria feature in Hibernate for getting the unique resultsets.

Upvotes: 0

Related Questions