【问题标题】:Hibernate get single row from the table with maximum field valueHibernate从具有最大字段值的表中获取单行
【发布时间】:2010-08-26 15:28:05
【问题描述】:

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

谢谢

【问题讨论】:

    标签: java hibernate orm hql


    【解决方案1】:

    Using Custom Query

    表结构:

    ID 保险名称投资金额投资日期

    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

    【讨论】:

      猜你喜欢
      • 2023-02-17
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 2018-11-28
      • 1970-01-01
      • 2020-04-16
      • 1970-01-01
      • 2021-03-30
      相关资源
      最近更新 更多