当前位置:编程学习 > JAVA >>

HQL返回一个集合对象如何解决

只想问HQL怎么写才是正确的。求高手回答下。

在数据库中类A类B是多对多关系

class A{
private List<B> bs ;//B是另一个类
private String name;
private int id;
private int age;

public A(int id ,String name ,int age,List<B> bs){
       this.id = id ;
       this.name = name;
       this.age = age;
       this.bs = bs;
}

}

在DAO层使用了hibernate框架

public List findAll(final int currentPage,final int numberPerPage) {
                //我想问下HQL可以这样写么?
String hql = "select new(id,name,age,bs) from A";
                //我还有一种想法是这样写的  
                //是为了懒加载的时候将数据查出来直接把字段当作参数传进构造方法中
                String  hql = "select new(id,name,age,new list(bs)) from A";
List as = Pages.pageList(hql, hibernateTemplate, currentPage, numberPerPage);
return as;

} --------------------编程问答-------------------- find(),该方法会直接返回List啊!
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,