LeaveJournalTable
emp_code emp_name leave_code leave_des leave_debit leave_credit
11 X AL openingbalace 5 0
11 X EL openingbalace 8 0
11 X EL allowance 10 0
11 X AL allowance 10 0
11 X AL Taken 0 2
11 X AL Taken 0 3
我想在Hibernate中创建一个查询
Query query = sessionfactory.getCurrentSession().createQuery("from LeaveOpenningJournal WHERE empCode = :empCode and " + "empName = :empName and " + "companyCode = :companyCode")
以及我想总结leave_credit字段GroupBy(leave_code,leave_des)
答案 0 :(得分:1)
请检查此代码:
Query listQuery = session.createSQLQuery("SELECT *,SUM(leave_credit) FROM LeaveOpenningJournal j WHERE mpCode = :empCode AND empName = :empName GROUP BY leave_code,leave_des");
listQuery.setParameter("empCode", "11");
listQuery.setParameter("empName", "x");
List<Object[]> parentChildMap = listQuery.list();
只需将parameter
和获取结果设置为list
。