我正在尝试使用JPA 2.1(Hibernate 4.3.5)调用数据库存储过程(Oracle 10g)。该过程在输出光标中返回结果:
PROCEDURE GET_EMPLOYEE(
P_ID_EMP IN VARCHAR2,
P_CURSOR OUT TYPES.cursor_type
)
AS ...
Java代码:
@NamedStoredProcedureQuery(name = "Employee.findById",
resultClasses = Employee.class,
procedureName = "GET_EMPLOYEE",
parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN, name = "P_ID_EMP", type = String.class),
@StoredProcedureParameter(mode = ParameterMode.REF_CURSOR, name = "P_CURSOR", type = void.class)
}
)
呼叫:
StoredProcedureQuery query = em.createNamedStoredProcedureQuery("Employee.findById");
query.setParameter("P_ID_EMP", "ID00001");
List<Employee> employees = query.getResultList(); //exception launched here
此异常已启动:
Exception in thread "main" java.lang.UnsupportedOperationException: org.hibernate.dialect.Oracle10gDialect does not support resultsets via stored procedures
at org.hibernate.dialect.Dialect.registerResultSetOutParameter(Dialect.java:1612)
at org.hibernate.engine.jdbc.cursor.internal.StandardRefCursorSupport.registerRefCursorParameter(StandardRefCursorSupport.java:94)
at org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.prepare(AbstractParameterRegistrationImpl.java:298)
at org.hibernate.procedure.internal.ProcedureCallImpl.buildOutputs(ProcedureCallImpl.java:417)
at org.hibernate.procedure.internal.ProcedureCallImpl.getOutputs(ProcedureCallImpl.java:378)
at org.hibernate.jpa.internal.StoredProcedureQueryImpl.outputs(StoredProcedureQueryImpl.java:251)
at org.hibernate.jpa.internal.StoredProcedureQueryImpl.getResultList(StoredProcedureQueryImpl.java:334)
使用Eclipselink 2.5.1(但不能使用它),相同的代码效果很好。
我知道我可以从entitymanager获取JDBC连接并使用经典的Resultset内容来检索结果,但我想使用JPA 2.1 - Hibernate。
谢谢。