hibernate SQLQuery结果存到 以MAP格式存放



查询sql: select col1,col2,col3 from table

代码如下

Java代码 
public List queryBySqlMap(String asql) {   
        final String sql = asql;   
        List lst = getHibernateTemplate().executeFind( new  HibernateCallback() {    
             public  Object doInHibernate(Session s)  throws  HibernateException, SQLException {    
                   Query query  =  s.createSQLQuery(sql).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);   
  
                   List list  =  query.list();    
                   return  list;    
                   }    
             });   
       return  lst;    
    }  

你可能感兴趣的:(Hibernate)