I have an Oracle function which return sys-refcursor and when I call this function using Hibernate, I am getting the following exception.
Hibernate: { ? = ca
JPA 2.1 early draft states that there will be support for stored procedures, according to Arun Gupta from Oracle.
Support for Stored Procedures: Added support for the invocation of predefined database functions and user-defined database functions to the Java Persistence query language.
There are different variants of
EntityManager.createXXXStoredProcedureQuery
methods that return a StoredProcedureQuery for executing a stored procedure. Just liked@NamedQuery
, there is@NamedStoredProcedureQuery
that specifies and names a stored procedure, its parameters, and its result type. This annotation can be specified on an entity or mapped superclass. The name specified in the annotation is then used inEntityManager.createNamedStoredProcedureQuery
. The IN, OUT, and INOUT parameters can be set and used to retrieve values passed back from the procedure. For example:
@Entity
@NamedStoredProcedureQuery(name="topGiftsStoredProcedure", procedureName="Top10Gifts")
public class Product {
. . .
}
// In your client
StoredProcedreQuery query = EntityManager.createNamedStoredProcedureQuery("topGiftsStoredProcedure");
query.registerStoredProcedureParameter(1, String.class, ParameterMode.INOUT);
query.setParameter(1, "top10");
query.registerStoredProcedureParameter(2, Integer.class, ParameterMode.IN);
query.setParameter(2, 100);
// there are other setParameter methods for defining the temporal type of a parameter
. . .
query.execute();
String response = query.getOutputParameterValue(1);
As for when the spec is going to be finalized, or when Hibernate will support JPA 2.1, I can't say. But it might be worth keeping an eye out.