No row with the given identifier exists:

最近在弄一个后台项目,有用到hibernate操作数据库.写hql语句表一对一关联查询的时候报这个错误.受到了csdn上一篇博客的启发,解决了我的问题.他的博客地址:http://blog.csdn.net/eyejava/article/details/1896492 


1.使用查询的hql语句

修正前:String hql="from MgjCardCommentEntity c left join c.userEntity user";
修正后:String hql="select c.id,user.id from MgjCardCommentEntity c left join c.userEntity user order by c.createTime desc";


这里只能查询出来这两张表的某些属性.我使用过right join查询,虽然不会报错但是结果集不理想.

这是我个人的总结,希望能帮到大家.有什么不正确的大家可以给我留言.