对于给定的两个日期范围,我有一个 MySQL StoredProcedure(EmployeeAbsentReport Procedure)。在 MySql 命令提示符上成功运行。如何使用 Hibernate 运行此存储过程,我找到了一个有关如何调用存储过程示例的示例,但在示例程序中,他使用了一个表。
程序:
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 := 0;
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 Master tp
JOIN daterange25 d
LEFT JOIN Transactions 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 ;
如何使用带有连接(包括临时表)的 Hibernate 调用存储过程并在 XML 映射文件中编写 sql-query?