Hibernate连表查询实例

  public ScrollableResults findStudent(String s)
    {
        try {
            String queryString = "select model.name from Student as model,StudentCj where model.cid=StudentCj.id and model.name=?" ;
            Query queryObject = getSession().createQuery(queryString);
      queryObject.setParameter(0, s);
      return queryObject.scroll();
         } catch (RuntimeException re) {
            log.error("find by property name failed", re);
            throw re;
         }
    }

 StudentDAO s=new StudentDAO();
ScrollableResults sc=s.findStudent("lisi");
while(sc.next())
{
  System.out.println(sc.getString("id"));
}

 

你可能感兴趣的:(hibernate,string,query)