如何写这个hql语句啊?public class ArticleSort implements java.io.Serializable { 
   private int sortId;  
   private java.lang.String sortName;   
   private java.util.Date createTime;  
   public User user;
   ...
}用户User 和 文章分类ArticleSort是一对多的关系,现在得到user对象,也知道分类名sortName,如何通过hql查询出来ArticleSort对象,怎么写hql语句:
select articleSort from ArticleSort as articleSort where articleSort.user ="+ user + " and articleSort.sortName = '"+sortName+"'";
这样写出现查询错误,怎么写才能正确?
where 里面对象如何比较?

解决方案 »

  1.   

    as去掉
    and articleSort.sortName =  "+sortName;
      

  2.   

    from ArticleSort articleSort where articleSort.user ="+ user + " and articleSort.sortName = "+sortName
      

  3.   

    where articleSort.user.id = user.getId()
      

  4.   

    String hql = "select articleSort from ArticleSort articleSort "+
                 "where articleSort.user =" + user + 
                 " and articleSort.sortName= "+sortName;
      

  5.   

    articleSort.user 是User对象,怎么用where中比较呢?
    类似#3楼那样写就可以了