Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java org.hibernate.exception.genericjdbception:执行此代码时无法执行查询异常_Java_Sql_Hibernate - Fatal编程技术网

Java org.hibernate.exception.genericjdbception:执行此代码时无法执行查询异常

Java org.hibernate.exception.genericjdbception:执行此代码时无法执行查询异常,java,sql,hibernate,Java,Sql,Hibernate,` 您好,我在执行此函数时遇到上述异常。在这里,我尝试获取特定列的不同部分。请帮我解决这个问题……`。提前谢谢 public List<Object[]> findDistinctProductBrand(){ SQLQuery squery =null; try{ Session session= sessionFactory.openSession(); squery =(SQLQuery) session.createSQLQue

`

您好,我在执行此函数时遇到上述异常。在这里,我尝试获取特定列的不同部分。请帮我解决这个问题……`。提前谢谢

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();
}  
公共列表findDistinctProductBrand(){
SQLQuery squery=null;
试一试{
Session Session=sessionFactory.openSession();
squry=(SQLQuery)session.createSQLQuery(“从ecm_产品中选择不同的产品_品牌”).addEntity(ecmpproduct.class).list();
}捕获(例外e){
System.out.println(“产品DAOImpl内部findDistinctproductBrand中的异常”+e);
}
返回squery.list();
}  

我认为你需要在你的代码中使用变压器。试一试:

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();
你可以跟着


让我知道它是否有效。

请添加完整的堆栈跟踪。