使用休眠查询

时间:2018-11-08 09:47:52

标签: java sql hibernate

我正在尝试对很多SQL使用休眠查询,有没有办法重写此sql以使其更整洁。我也在变数,从未使用过'Query paymentdate'

  public void addPrevious(TodaysDate Date){
            String paymentDate = ("SELECT PAYMENTDATE FROM table1  where DATE = (SELECT ID FROM _DATE WHERE ID = ( SELECT MAX(ID) FROM _DATE WHERE ID < ( SELECT MAX(ID) FROM _DATE ) ))");
            String reportingUnit = ("SELECT REPORTING_UNIT FROM table1  where DATE = (SELECT ID FROM _DATE WHERE ID = ( SELECT MAX(ID) FROM _DATE WHERE ID < ( SELECT MAX(ID) FROM _DATE ) ))");
            String insertLastDate =  ("INSERT INTO table1(PAYMENTDATE, REPORTING_UNIT, Date) VALUES  ("+id+" ,"+paymentDate+", "+amount+", "+asOfDate+")");

            Query paymentdate = getSession().createQuery(paymentDate);
            Query report = getSession().createQuery(reportingunit);

        }

0 个答案:

没有答案