I am trying to translate this hql query:
Code:
select distinct ci.savingType from CalculationItem as ci where ci.currency=?
into Criteria API query.
So far , this is the best that I can do:
Code:
Criteria cr = sessionFactory.getCurrentSession().createCriteria(CalculationItem.class);
if(currency!=null)
{
cr.add(Restrictions.eq("currency", currency));
}
cr= cr.createCriteria("savingType", "st").setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
List<Map> firstList = cr.list();
List<SavingType> list= new ArrayList<SavingType>();
for (Map<String, SavingType> type : firstList)
{
SavingType one = type.get("st");
if(!list.contains(one))
{
list.add(one);
}
}
return list;
Is there any better way to to this. I would like to avoid "manual" filtering of duplicate SavingType objects.
Thanx!