繁体   English   中英

使用休眠的存储过程

[英]Stored procedure using hibernate

我想使用存储过程来添加和删除使用休眠的分层数据。 为此,我想首先检查该过程是否存在于数据库中,如果不存在,则创建它。 我寻找在休眠中执行此操作的标准方法,但一无所获。 我只是想知道使用 hibernate 创建过程是否好,或者是否有更好的方法在 hibernate 中对分层数据进行操作。

我正在从我的应用程序调用 webservice,该应用程序使用存储过程以分层格式返回数据。 如果该过程在运行时不知不觉中被删除,我的应用程序将永远无法检索数据。 所以如果程序不存在,我想要什么创建它。 我不确定这是否正确? 我需要指导...

您可以按如下方式在 Hibernate 中调用存储的函数或过程,

session.doWork(new Work() {
  public void execute(Connection connection) throws SQLException {
    CallableStatement call = connection.prepareCall("{ ? = call MYSCHEMA.MYFUNC(?,?) }");
    call.registerOutParameter( 1, Types.INTEGER ); // or whatever it is
    call.setLong(2, id);
    call.setLong(3, transId);
    call.execute();
    int result = call.getInt(1); // propagate this back to enclosing class
  }
});

相似地

int result = session.doReturningWork(new ReturningWork<Integer>() {
  @Override
   public Integer  execute(Connection connection) throws SQLException {
    CallableStatement call = connection.prepareCall("{ ? = call MYSCHEMA.MYFUNC(?,?) }");
    call.registerOutParameter( 1, Types.INTEGER ); // or whatever it is
    call.setLong(2, id);
    call.setLong(3, transId);
    call.execute();
    return call.getInt(1); // propagate this back to enclosing class
  }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM