[英]org.hibernate.exception.GenericJDBCException: could not execute query Exception while executing this code
` `
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 .我认为您需要在您的代码中使用 Transformers。 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.让我知道它是否有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.