本文介绍了Hibernate:如何从多个类的查询中获得结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我的查询包含一个类,比如:
query = session.createQuery(select User from u );
queryResult = query.list();
然后迭代它,其中 queryResult
是一个 User
类的对象。
那么如何从包含多个类的查询中得到结果呢?例如:
从User中选择u,g作为u,Group作为g,其中u.groupId = g.groupId和g。 groupId = 1
解决方案
for(Object [] result:query.list()){
User user =(User)result [0];
Group group =(Group)result [1];
}
If my query contains one class, like:
query = session.createQuery("select u from User as u");
queryResult = query.list();
then I iterate it, where queryResult
is an object of User
class.
So how to get result from query which contains more than one class? For example:
select u, g from User as u, Group as g where u.groupId = g.groupId and g.groupId = 1
解决方案
for (Object[] result : query.list()) {
User user = (User) result[0];
Group group = (Group) result[1];
}
这篇关于Hibernate:如何从多个类的查询中获得结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!