Skip to content

Instantly share code, notes, and snippets.

@sangimed
Created October 4, 2018 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sangimed/92543f4e095b6861ce3b200e9b2eb19d to your computer and use it in GitHub Desktop.
Save sangimed/92543f4e095b6861ce3b200e9b2eb19d to your computer and use it in GitHub Desktop.
Call a plsql procedure with JPA in Spring
package mypackage;
import javax.persistence.EntityManager;
import javax.persistence.ParameterMode;
import javax.persistence.PersistenceContext;
import javax.persistence.StoredProcedureQuery;
import org.springframework.stereotype.Component;
@Component
public class ProcedureQueries {
@PersistenceContext
private EntityManager entityManager;
public String myfunc(final String param) {
StoredProcedureQuery query = entityManager.createStoredProcedureQuery("plsql_procedure_name")
.registerStoredProcedureParameter("pram", String.class, ParameterMode.IN)
.registerStoredProcedureParameter("result", String.class, ParameterMode.OUT)
.setParameter("pram", param);
query.execute();
return (String) query.getOutputParameterValue("result");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment