`
Hi, I am getting above Exception while executing this function.Here i am trying to fetch distinct of a particular column. Please help me solve this issue...`.Thanks in advance.
public List<Object[]> findDistinctProductBrand(){
SQLQuery squery =null;
try{
Session session= sessionFactory.openSession();
squery =(SQLQuery) session.createSQLQuery("select distinct product_brand from ecm_product").addEntity(EcmProduct.class).list();
}catch(Exception e){
System.out.println("Exception in ProductDaoImpl inside findDistinctproductBrand "+e);
}
return squery.list();
}
I think you need to use Transformers in ur code . give it a Try:
String sql = "select distinct product_brand from ecm_product";
//or String sql = "select distinct(product_brand) from ecm_product";//no difference actually
SQLQuery query = session.createSQLQuery(sql);
query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
List results = query.list();
and you may follow this
Let me know if it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.