hebernate的hql查询:
两个表主要结构:
Testpathbpel 主要有id和testpath
public class Testpathbpel {
private Integer id;
private String testpath;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTestpath() {
return testpath;
}
public void setTestpath(String testpath) {
this.testpath = testpath;
}
}
Testcasebpel 主要有id(主键),TestPathbpel的id(外键),testcase
public class Testcasebpel {
private Integer id;
private Testpathbpel testpathbpel;
private String testcase;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Testpathbpel getTestpathbpel() {
return testpathbpel;
}
public void setTestpathbpel(Testpathbpel testpathbpel) {
this.testpathbpel = testpathbpel;
}
public String getTestcase() {
return testcase;
}
public void setTestcase(String testcase) {
this.testcase = testcase;
}
}
查询Testcasebpel所有:
public List<Testcasebpel> getAll()
{
String hql="FROM Testcasebpel t LEFT OUTER JOIN FETCH t.testpathbpel";
Session session = getSession();
List<Testcasebpel> list = session.createQuery(hql).list();
session.close();
return list;
}
按照外键 查询Testcasebpel符合条件的记录:
public List<Testcasebpel> getSelectAll(Testpathbpel testpathbpel)
{
Session session = getSession();
String hql="FROM Testcasebpel t LEFT OUTER JOIN fetch t.testpathbpel where t.testpathbpel.id = ?";
List<Testcasebpel> list = session.createQuery(hql).setInteger(0, testpathbpel.getId()).list();
session.close();
return list;
}