gpt4 book ai didi

java - Hibernate 从表中获取具有最大字段值的单行

转载 作者:行者123 更新时间:2023-12-02 08:30:21 24 4
gpt4 key购买 nike

在 Hibernate 中,如何从表中获取具有最大字段值的单行?

谢谢

最佳答案

Using Custom Query

表结构:

ID insurance_name invested_amount investement_date

public class HibernateHQLMaxFunction {

public static void main(String[] args) {
// TODO Auto-generated method stub

Session sess = null;
try {
SessionFactory fact = new
Configuration().configure().buildSessionFactory();
sess = fact.openSession();
String SQL_QUERY = "select
max(FIELD_NAME)from Insurance insurance";
Query query = sess.createQuery(SQL_QUERY);
List list = query.list();
System.out.println("Max
Invested Amount: " + list.get(0));
sess.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}

来自 here

关于java - Hibernate 从表中获取具有最大字段值的单行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3576648/

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