我正在尝试对很多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);
}