'JPA - Call oracle package and return integer

I'm tryng to execute oracle package function that return integer. Below the code that I'm using.

When execute method is invoked I get this error:

StoredProcedureQuery spq = em.createStoredProcedureQuery(functionName);
spq.registerStoredProcedureParameter(0, Object.class, ParameterMode.IN);
spq.registerStoredProcedureParameter(1, Object.class, ParameterMode.IN);
spq.registerStoredProcedureParameter(2, Object.class, ParameterMode.IN);

spq.setParameter(0,1);
spq.setParameter(0,"a");
spq.setParameter(0,"b");

spq.execute();

org.hibernate.MappingException: Unknown entity: java.lang.Integer

The code is inside a method that could guarantees execution of more package,which is mandatory, with a dynamic number of parameter. In the example I removed, for simplicity, the for statement.



Solution 1:[1]

The solution is:

using Hibernate type instead of Java types

import org.hibernate.type.DateType;
import org.hibernate.type.IntegerType;
import org.hibernate.type.StringType;
....
StoredProcedureQuery spq = em.createStoredProcedureQuery(functionName);
spq.registerStoredProcedureParameter(0, Object.class, IntegerType.IN);
spq.registerStoredProcedureParameter(1, Object.class, DateType.IN);
spq.registerStoredProcedureParameter(2, Object.class, StringType.IN);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ciro