请教一下这句HQL语句对不对,如果不对的话,请您给出正确的,谢谢……
String sql = "select a from AbroadExpert a,Resume r where 1=1 ";
if(queryExpertInfo.getWorkId() != 0) {
sql += " and a.id = ('select r.expertId from resume r where r.work.id =:"  +queryExpertInfo.getWorkId()+ "')";

}

解决方案 »

  1.   

    是这样的我把类简化一下
    AbroadExpert {
     private int id;
      private Set<Resume> resume;
    }
    Resume {
      private Work work;
      private int expertId;  //关联AbroadExpert的id  
    }
    Work{
      private int id;
      private String name;
    }
      

  2.   

    改为:
    String sql = "select a from AbroadExpert a,Resume r where 1=1 "; 
    if(queryExpertInfo.getWorkId() != 0) { 
    sql += " and a.id in (select r.expertId from resume r where r.work.id ='"  +queryExpertInfo.getWorkId()+ "')"; }
      

  3.   

    sql += " and a.id = (select r.expertId from Resume r where r.work.id ="  +queryExpertInfo.getWorkId()+ ")";
      

  4.   

    上面的有点问题,应改为:
    sql += " and a.id = (select r.expertId from Resume r where r.work.id ="  +queryExpertInfo.getWorkId()+ ")";
      

  5.   

    你写的两次 好像是一摸一样的 
    我按照这个运行的时候,老报错:不知道为什么?
    严重: Servlet.service() for servlet action threw exception
    org.hibernate.QueryException: could not resolve property: expertId of: com.expert.domain.model.Resume [select a from com.expert.domain.model.AbroadExpert a where 1=1  and a.id = (select r.expertId from com.expert.domain.model.Resume r where r.work.id ='1')]
      

  6.   

    你的Resume 这个类在哪个包里怎么生成的sql语句提示com.expert.domain.model.Resume 在这里????
      

  7.   

    Resume这个类就在com.expert.domain.model包里面
      

  8.   

    could not resolve property: expertId of: com.expert.domain.model.Resume
    我只知道 你这个错误的意思是 不能识别的属性  expertId