Hibernate: How to get result from query with multiple classes

后端 未结 4 827
眼角桃花
眼角桃花 2020-12-23 17:09

If my query contains one class, like:

query = session.createQuery(\"select u from User as u\");
queryResult = query.list();

then I iterate

4条回答
  •  攒了一身酷
    2020-12-23 17:45

    Also you can create a constructor and return a object:

    Assuming that the class Family has an appropriate constructor - as an actual typesafe Java object:

    select new Family(mother, mate, offspr)
    from DomesticCat as mother
    join mother.mate as mate
    left join mother.kittens as offspr
    

    Or a list:

    select new list(mother, offspr, mate.name)
    from DomesticCat as mother
    inner join mother.mate as mate
    left outer join mother.kittens as offspr
    

    http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html#queryhql-select

提交回复
热议问题