我们如何使用 Hibernate 和 JPA 调用存储过程? [英] How can we call a stored procedure with Hibernate and JPA?
本文介绍了我们如何使用 Hibernate 和 JPA 调用存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何使用 Hibernate 或 JPA 调用存储过程?
How can we call a stored procedure using Hibernate or JPA?
推荐答案
您可以进行以下操作
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.
这篇关于我们如何使用 Hibernate 和 JPA 调用存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文