java.lang.ClassCastException: org.hibernate.impl.SQLQueryImpl cannot be cast to java.util.List

来源:互联网 发布:centos7修改ssh端口号 编辑:程序博客网 时间:2024/06/05 00:12

使用hibernate时遇到的类型转化问题


正确流程是


1、sql语句

2、创建Query对象

3、使用list类进行接收


这样就不存在查询结果转化为list出现问题的错误了


hibernate使用sql语句的搜索流程


public List<Request> getListOfTransno(String id) {String sql = "select p.* from request p where p.id=?";//查数据进行验证Query query = this.getSession().createSQLQuery(sql).addEntity(Request.class);query.setFirstResult(0);query.setString(0, id);@SuppressWarnings("unchecked")List<PayRequestInfo> list = query.list();return list;}



hibernate使用hql语句搜索的流程


0 0