Java - 使用Hibernate调用存储过程 - 无法返回结果集

时间:2013-08-02 09:44:43

标签: java mysql hibernate jdbc mysql-error-1312

我正在学习本教程(http://www.mkyong.com/hibernate/how-to-call-store-procedure-in-hibernate/),使用Hibernate在Java中调用SQL存储过程。但是,我遇到了一个恼人的错误。

在我的hibernate映射文件中,我有以下几行:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
<class name="jcolibri.examples.ABXRecommender.ABXDescription"
    table="currpatdata">
    <id name="caseId" column="caseId">
        <generator class="native" />
    </id>
    <property name="PatientId" column="PatientId" />
    <property name="Hospital" column="Hospital" />
    <property name="HospNumber" column="HospNumber" />
</class>
<sql-query name="GetCurrPatByHospNo">
    <return alias="currpatdata" class="jcolibri.examples.ABXRecommender.ABXDescription"/>
    <![CDATA[CALL get_curr_pat_by_Hosp_No(:HospNumber)]]>
</sql-query>

我有以下存储过程:

DELIMITER $$

CREATE PROCEDURE `get_curr_pat_by_Hosp_No`(IN hospno VARCHAR(255))
BEGIN
SELECT * FROM `kmdata`.`currpatdata` WHERE HospNumber = hospno;
END $$

DELIMITER ;

我可以成功致电:

call get_curr_pat_by_Hosp_No('SM1997');

在我的Java代码中,我有

Query query = session.getNamedQuery("GetCurrPatByHospNo").setParameter("HospNumber", "SM1997");
List result = query.list();

但是,这会导致我的控制台出现以下错误(并打印出来):

Hibernate: CALL get_curr_pat_by_Hosp_No(?)
WARN [main] (JDBCExceptionReporter.java:77) - SQL Error: 1312, SQLState: 0A000
ERROR [main] (JDBCExceptionReporter.java:78) - null,  message from server: "PROCEDURE kmdata.get_curr_pat_by_Hosp_No can't return a result set in the given context"
ERROR [main] (DataBaseConnector.java:285) - org.hibernate.exception.GenericJDBCException: could not execute query

有没有人有任何想法?

干杯, 凯什

0 个答案:

没有答案