1

I am using Hibernate JPA. I have below Oracle Stored procedure.

CREATEORREPLACEPROCEDURE PROC_AB
(
      in_name VARCHAR2,
      in_lastname VARCHAR2,
      out_emp_id OUTINTEGER
)

How can I invoke this stored procedure?

Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
user755806
  • 6,565
  • 27
  • 106
  • 153

1 Answers1

1

Check this SO question:

  1. First you define the stored procedure named native query:

    @javax.persistence.NamedNativeQuery(name = "call_proc_ab", query = "{ call PROC_AB(:cmpid,:status,?) }", resultClass = Long.class, hints = {
    @javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") })
    
  2. Then you execute it using:

    TypedQuery<Long> query = entityManager.createNamedQuery("call_proc_ab", Long.class); 
    query.setParameter("cmpid",cmpid); 
    query.setParameter("status",status); 
    Long empId = query.getSingleResult(); 
    
Community
  • 1
  • 1
Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911