hibernate 内查询 fetch

来源:互联网 发布:js方法执行顺序 编辑:程序博客网 时间:2024/06/08 00:24

有fetch的查询

String sqlString =

"from Votecontext as vc join fetch vc.vote as vo where vo.voteId=? ";//

List list = getHibernateTemplate().find(sqlString, voteId);

for (int i = 0; i < list.size(); i++) {

Votecontext vc = (Votecontext) list.get(i);

System.out.println(vc.getContext());

System.out.println(vc.getVote().getTitle()); //通过Vote查找title

}

当查询语句缺少fetch时候

获取结果如下

for (int i = 0; i < list.size(); i++){

Object[] obj = (Object[]) list.get(i);

Votecontext vc = (Votecontext) obj[0];

context = vc.getVontext();

Vote vote =(Vote)obj[1];

title =vote.getTitle();