I can't add SELECT DISTINCT taxtCode
from this code:
public List<TblTaxType> findAlltaxtCode(String bfnsCode) {
List<TblTaxType> result = null;
String hql = "select distinct(taxtCode) from TblTaxType tbl_tax_type WHERE bfnsCode = ?";
try {
setSession(HibernateUtil.getSession());
@SuppressWarnings("unchecked")
List <TblTaxType> resultList = getSession().createQuery(hql)
.setString(0, bfnsCode)
.list();
if(!resultList.isEmpty()){
result = resultList;
Debugger.print("TAX CODES FOUND ");
}else{
Debugger.print("TAX CODES NOT FOUND ");
}
} catch (Exception e) {
e.printStackTrace();
Debugger.print(" TAX CODES NOT FOUND ");
}
Debugger.print(hql);
closeSession();
return result;
}
Updated into whole code. The query is right but it seems its not returning a list value. Still java.lang.String cannot be cast to com.test.test.TblTaxType
error appearing. How this query returns a list of value? The error occurs whenever a word DISTINCT is added. Is it impossible in HQL to use a distinct and return a list of value like in SQL Query?