我在休眠3中使用join和where子句,但是我无法达到解决方案。我得到了错误。

Query qry= session.createQuery("SELECT addemployee.eid,addemployee.fname,addemployee.location,"
        + "empdet.jtitle,empdet.leadname FROM addemployee LEFT JOIN empdet ON addemployee.eid = empdet.eid WHERE (addemployee.eid ='"+id+"')");

        List l = qry.list();
        Iterator it=l.iterator();

        while(it.hasNext())
        {

            Object rows[] = (Object[])it.next();
            System.out.println(rows[0]+separator+rows[1]+separator+rows[2]+separator+rows[3]+separator+rows[4]);
        }


问题:org.hibernate.hql.ast.QuerySyntaxException:意外令牌:在第1行,第127列附近[选择addemployee.eid,addemployee.fname,addemployee.location,empdet.jtitle,empdet.leadname FROM addemployee LEFT JOIN empdet在addemployee上.eid = empdet.eid,位置(addemployee.eid ='206')]

最佳答案

尝试改用session.createSQLQuery()

并且不要在输入中加上单引号(''),而是输入numbers,而不是varchar

像这样。

Query qry= session.createSQLQuery("SELECT addemployee.eid,addemployee.fname,addemployee.location,"
    + "empdet.jtitle,empdet.leadname FROM addemployee LEFT JOIN empdet ON addemployee.eid = empdet.eid WHERE (addemployee.eid ="+id+")");

10-01 17:01