gpt4 book ai didi

java - hibernate SQLquery 提取变量

转载 作者:行者123 更新时间:2023-12-03 20:25:01 27 4
gpt4 key购买 nike

如何从 hibernate SQL 查询中提取变量 total、min、max 并将它们分配给 java 变量?

(select count(*) as total, min(price) as min, max(price) as max from product).addScalar("total", Hibernate.INTEGER).addScalar("min", Hibernate.INTEGER).addScalar("max", Hibernate.INTEGER);

最佳答案

This帖子应该对你有帮助。

稍后编辑:

String sQuery = "select min(myEntity.x), max(myEntity.y) from MyEntity myEntity";
Query hQuery = session.createQuery(sQuery);
List result = hQuery.list();

Iterator iterator = result.iterator();

while (iterator.hasNext()) {
Object[] row = (Object[])iterator.next();
for (int col = 0; col < row.length; col++) {
System.out.println(row[col]);
}
}

关于java - hibernate SQLquery 提取变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3435588/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com