如何通过hibernate调用存储过程

2025-04-30 20:51:28
推荐回答(2个)
回答1:

不支持。用hibernate,就不要用NativeSQL,至少不要在同一个session内混用,存储过程也是native的

回答2:

getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) {
try {
Connection conn = session.connection();

String sql = "{call readcountplusone(?)}";
CallableStatement stmt = conn.prepareCall(sql);
stmt.setLong(1, pojo.getId().longValue());
stmt.execute();
} catch (Exception e) {

e.printStackTrace();
}
}

return null;
}
});
使用spring提供的getHibernateTemplate调用