2 yjwzsrzj YJWZSRZJ 于 2017.09.10 19:29 提问

hibernate 数据查询,查不出来
    @Action(value = "json")
    public void json() {
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpServletResponse response = ServletActionContext.getResponse();
         Session session=sessionFactory.openSession();
           Query<Object[]> query=session.createQuery("select r.rnid, r.rnumber,r.rstate,u.uid,u.uname,u.ucard,u.uphone,u.count,u.ustaydate,u.uenddate from roomnumber r left join r.listuser u");
            List<Object[]> room=query.list();
            System.err.println(room);
            List<User_Roomnumber> list=new ArrayList<User_Roomnumber>();
            for (Object[] objects : room) {
                User_Roomnumber user=new User_Roomnumber();
                user.setRnid((Integer) objects[0]);
                user.setRnumber((Integer) objects[1]);
                user.setRstate((Integer) objects[2]);
                user.setUid((Integer) objects[3]);
                user.setUname((String) objects[4]);
                user.setUcard((String) objects[5]);
                user.setUphone((String) objects[6]);
                user.setUcount((Integer)objects[7]);
                user.setUstaydate((String) objects[8]);
                user.setUenddate((String) objects[9]);
                list.add(user);
            }   
            session.beginTransaction().commit();
            session.close();
            String data = JSON.toJSONString(list);
        try {
            response.setCharacterEncoding("UTF-8");
            PrintWriter out = response.getWriter();
            out.write(data);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    后台代码
 $(function(){
    $("#dg").edatagrid({
        pageList:[5,10,20],
        fitColumns :true,
        pageSize:5,
        url:'json.action',
        remoteSort: false,
        pagination:true,
        toolbar:'#toolbar',
        columns:[[
                  {field:'bi_id',title:'编号',width:80},
                  {field:'bi_date',title:'日期',width:80,
                  formatter:function(value,row,index){  
                      var unixTimestamp = new Date(value);  
                      return unixTimestamp.toLocaleDateString(); 
                      }  },       
                  {field:'uname',title:'用户名字',width:30,editor:{type:'text',options: {required: true}}},
                  {field:'ucard',title:'身份证号',width:50,editor:{type:'text',options: {required: true}}},
                  {field:'uphone',title:'手机号',width:40,editor:{type:'text',options: {required: true}}},
                  {field:'ucount',title:'入住人数',width:30,editor:{type:'text',options: {required: true}}},
                  {field:'rnid',title:'房间号',width:30,editor:{type:'text',options: {required: true}}},
                  {field:'ustaydate',title:'入住时间',width:30,editor:{type:'text',options: {required: true}}},
                  {field:'uenddate',title:'退房时间',width:30,editor:{type:'text',options: {required: true}}},
              ]]
    })
    var row = $('#dg').datagrid('reload');
}); 

报错信息:
java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: count of: com.entity.UserEntity [select r.rnid, r.rnumber,r.rstate,u.uid,u.uname,u.ucard,u.uphone,u.count,u.ustaydate,u.uenddate from com.entity.RoomnumberEntity r left join r.listuser u]

2个回答

Oh_my_godness
Oh_my_godness   2017.09.11 09:44

远观是你的sql的问题不能编译

YJWZSRZJ
YJWZSRZJ 确实
2 个月之前 回复
wgs1393044648
wgs1393044648   2017.09.11 22:49

from后写model类名

Csdn user default icon
上传中...
上传图片
插入图片