I tried to utilize Hibernate 4.3.5 (JPA2.1) to invoke Oracle (11.2 v) Stored Procedure within Springframework4.0.1. I am unable to find sample code using dynamic StoredProcedureQuery to call Oracle SP. Based on JPA 2.1 I wrote following code, run it in eclipse utilizing Tomcat 7.0.53 and got below error:
Hibernate: {call GET_CRIS_SMS(?)} WARN warn - Handler execution resulted in exception java.lang.UnsupportedOperationException: org.hibernate.dialect.Oracle10gDialect does not support resultsets via stored procedures
Here are my code and config:
-- SP
PROCEDURE GET_CRIS_SMS(P_REF_CURSOR OUT REF CURSOR) IS BEGIN OPEN P_REF_CURSOR FOR SELECT SMS_MSG_ID, APP_NAME, MOBILE_PHONE, COUNTRY_CD, SMS_MSG FROM CRIS_SMS; EXCEPTION WHEN OTHERS THEN RAISE_APPLICATION_ERROR(-20001, 'No records found '); END;
-- java
@PersistenceContext private EntityManager em;
StoredProcedureQuery storedProcedure = em.createStoredProcedureQuery("GET_CRIS_SMS"); storedProcedure.registerStoredProcedureParameter("customers", void.class, ParameterMode.REF_CURSOR); boolean b = storedProcedure.execute(); if (b == true){ Object obj = storedProcedure.getOutputParameterValue("customers"); }
The exception was thrown from storedProcedure.execute()
-- config
<!-- JPA EntityManagerFactory --> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:dataSource-ref="dataSource"> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" p:databasePlatform="${hibernate.dialect}" p:database="${jpa.database}" p:showSql="${jpa.showSql}"/> </property> <!-- gDickens: BOTH Persistence Unit and Packages to Scan are NOT compatible, persistenceUnit will win --> <property name="persistenceUnitName" value="petclinic"/> <property name="packagesToScan" value="org.springframework.samples.petclinic"/> </bean>
where hibernate.dialect is org.hibernate.dialect.Oracle10gDialect
Thanks a lot for your help!
|