hibernage 报不能转换成 对象

来源:互联网 发布:淘宝搜索店铺名找不到 编辑:程序博客网 时间:2024/06/06 00:02

首先你要在你的类中写好,这个,供映射用的

public User(){}
    
    public User(String phone,String address,Long id){
        this.phone=phone;
        this.address=address;
        this.id=id;
    }

然后在你的hibernate查询语句,写上这个,,,,这里你是转为一个User对象,所以结果要是唯一的

String hql = "select new User(phone,address) from User u where u.id='"+id+"'";
        Query query = (Query) this.getSession().createQuery(hql);
        return (User) query.uniqueResult();

0 0