我有一个 MySQL 存储过程,它接受两个输入日期并返回EmpCode
、Name
、Department
和Employee_Absent_Date
Total_No_OF_Days
存储过程(两个给定日期范围内的员工缺勤报告):
DELIMITER $$
DROP PROCEDURE IF EXISTS `AbsentReportproc`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `AbsentReportproc`(IN _fromdate DATETIME, IN _todate DATETIME)
BEGIN
CREATE TEMPORARY TABLE daterange25 (dte DATE);
SET @counter := -1;
WHILE (@counter < DATEDIFF(DATE(_todate), DATE(_fromdate))) DO
INSERT INTO daterange25 VALUES (DATE_ADD(_fromdate, INTERVAL @counter:=@counter + 1 DAY));
END WHILE;
SELECT tp.EMPCODE,tp.NAME,tp.DEPARTMENT, Group_Concat(d.dte order by d.dte SEPARATOR '\n')AbsentDate, COUNT(tp.EMPCODE) Totalnoofabsentdates
FROM test_prefixmaster tp
JOIN daterange25 d
LEFT JOIN test_prefixtransactions tpt ON (tp.EMPCODE = tpt.empcode) AND DATE(S_DateTime) = d.dte
WHERE tpt.empcode IS NULL
GROUP BY tp.EMPCODE;
DROP TABLE daterange25;
END$$
DELIMITER ;
这是我的休眠映射文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="edu.model.Master" table="test_prefixmaster">
<id name="empcode" column="EMPCODE" length="10" ></id>
<property name="dept">
<column name="DEPARTMENT" length="30" />
</property>
<property name="empname">
<column name="NAME" length="30" />
</property>
</class>
<sql-query name="AbsentReportproc" callable="true">
<return alias="master" class="edu.model.Master">
<return-property name="empcode" column="EMPCODE" />
<return-property name="dept" column="DEPARTMENT" />
<return-property name="empname" column="NAME" />
</return>
<![CDATA[CALL AbsentReportproc(:_fromdate,:_todate)]]>
</sql-query>
</hibernate-mapping>
这是我的测试类(主要):
public static void main(){
Query query = session.getNamedQuery("AbsentReportproc");
query.setParameter("_fromdate", "2012-11-22");
query.setParameter("_todate", "2012-11-23");
List absentiesList=new ArrayList();
absentiesList = query.list();
for (int i = 0; i < absentiesList.size(); i++) {
Master master = (Master) absentiesList.get(i);
System.out.println("Employee Code:::" + master.getEmpcode());
System.out.println("Employee Name:::"master.getEmpname());
System.out.println("Employee Department:::" + master.getDept());
}
}
当我运行我的休眠代码时,我能够成功打印员工代码、姓名和部门
但我的实际要求是如何映射列并从名为 的临时表中打印 d.dte 的值daterange25
?我应该为我的临时表创建一个 Pojo 吗?
谢谢