[英]Combine two SQL query calls into one in Hibernate
I have a stored procedure named find_slow_persons()
that returns a table with two columns: 我有一个名为
find_slow_persons()
的存储过程,该存储过程返回具有两列的表:
RETURNS TABLE(
person_id BIGINT,
time_late_by DOUBLE PRECISION
)
and with Hibernate, I can obtain these 2 column's values as List
with 2 calls: 使用Hibernate,我可以通过2次调用以
List
获取这2列的值:
SQLQuery query =
session.createSQLQuery("select * from find_slow_persons()").addScalar("person_id", LongType.INSTANCE);
SQLQuery time =
session.createSQLQuery("select * from find_slow_persons()").addScalar("time_late_by",
LongType.INSTANCE);
List<Long> duplicateDataPointIds = query.list();
List<Long> timeBy = time.list();
Now I got the 2 lists of the data I want, is there a way to combine these 2 and only make 1 query ? 现在我得到了我想要的数据的2个列表,有没有办法组合这2个并且只进行1个查询?
Is there a reason you're separating the column into two queries? 您将列分为两个查询是有原因的吗? The following should have the desired effect if not:
如果没有以下效果,则应达到预期效果:
session.createSQLQuery("select * from find_slow_persons()")
.addScalar("person_id", LongType.INSTANCE)
.addScalar("time_late_by", LongType.INSTANCE)
// returns an object[] List you'll have to unpack
List duplicateDataPointIds = query.list();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.