使用hibernate从java调用具有多个输出参数的存储过程

时间:2015-01-10 16:24:29

标签: java oracle hibernate stored-procedures hibernate-mapping

我正在尝试使用hibernate调用存储过程。这是映射: -

<hibernate-mapping>
   <sql-query name="myprocedure" callable="true">
    <return alias="ev" class="TestDataBean">
        <return-property name="city" column="CITY"/>
        <return-property name="country" column="COUNTRY"/>
    </return>
    <![CDATA[CALL  myprocedure(?,?)]]>
</sql-query>
</hibernate-mapping>

存储程序是:

create or replace 
PROCEDURE myprocedure(
    CITY OUT VARCHAR,
    COUNTRY OUT VARCHAR)
IS
BEGIN
  SELECT * INTO CITY,COUNTRY
  FROM TESTTABLE

END myprocedure;

Java代码是:

Transaction tx = session.beginTransaction();
Query query = session.getNamedQuery("myprocedure");
List results = query.list();
for (Object object : results) {
    TestDataBean test = (TestDataBean)object;
}

但我得到了这个例外:

Exception in thread "main" org.hibernate.HibernateException: Errors in named queries:myprocedure
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:545)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
at CallStoredProcedure.callOracleStoredProcOUTParameter(CallStoredProcedure.java:37)
at CallStoredProcedure.main(CallStoredProcedure.java:29)

0 个答案:

没有答案