我的maintain_info表与account表是多对一的关系,它们的POJO类分别是MaintainInfo和Account. 
MaintainInfo中有Account类型的对象,Account中有装有MaintainInfo对象的Set集合. 
现在我想进行如下查询: 
String hql = "from MaintainInfo where account="+account; 
其中account是Account类的对象,请问大家这个hql语句应该怎样改才正确?

解决方案 »

  1.   

    对象应该有标识吧?应该通过标识查询,比如id等,你那样是多此一举,既然已经得到account对象了,还要去数据库查一下吗?直接通过get()方法得到就是了
      

  2.   

    或者是String hql = "from MaintainInfo where account.id="+account.getId(); 
      

  3.   

    String hql = "select m from MaintainInfo m where m.account="+account;
      

  4.   

    在hibernate的配置文件中加入,one-to-many
      

  5.   

    你们说的都不对,应该是改成String hql = "from MaintainInfo where account="+accountId;