How can we call a stored procedure with Hibernate and JPA?

后端 未结 7 1364
时光取名叫无心
时光取名叫无心 2020-12-15 06:34

How can we call a stored procedure using Hibernate or JPA?

相关标签:
7条回答
  • 2020-12-15 07:30

    You can do the following

     Session session = sessionFactory.openSession();
    Transaction tx = session.beginTransaction();
    PreparedStatement st = session.connection().prepareStatement("{call procedureName(?, ?)}");
                    st.setString(1, formatter.format(parameter1));
                    st.setString(2, formatter.format(parameter2));
                    st.execute();
    tx.commit();
    

    Please add the exception handling wherever required.

    0 讨论(0)
提交回复
热议问题