【问题标题】:Passing user defined list from hibernate to oracle stored procedure将用户定义的列表从休眠传递到 oracle 存储过程
【发布时间】:2012-12-08 00:46:00
【问题描述】:

我想从我的休眠类传递一个用户定义的对象,并将它传递给一个存储过程,该过程读​​取这个对象列表并进行处理。我该怎么做?

类如下。

public class ExcelListenerBean {
    private int id;
    private String shortName;
    private String fmrCusip;
    private Double incorrectTrdShares;
    private Double incorrectTrdPrice;
    private String incorrectTrdBuySell;
    private Double incorrectTrdCommRate;
    private Double incorrectTrdCommission;
    private Double incorrectTrdFees;
    private Double incorrectTrdNet;
    private Double correctionTrdShares;
    private Double correctionTrdPrice;
    private String correctionTrdBuySell;
    private Double correctionTrdCommRate;
    private Double correctionTrdCommission;
    private Double correctionTrdFees;
    private Double correctionTrdNet;
    private String currency;
    private String fx;
    private Double netUSD;
    private String notes;
}

谁能告诉我如何起草程序以及如何遍历 ExcelListenerBean 对象列表并将它们保存到表格中。

【问题讨论】:

  • 谁能给我代码 sn-p 来概述存储过程,基本上是遍历 TableOfExcelListenerBean 对象的数组。我对 SP 还很陌生,在写一篇文章时遇到了麻烦。

标签: java oracle hibernate stored-procedures orm


【解决方案1】:
  1. 在 Oracle 中创建 OBJECT 类型,例如 MyType is OBJECT ....,其中包含您需要的所有字段
  2. 创建集合类型,TableOfMyObject IS TABLE OF MyObjectType
  3. 创建以TableOfMyObject 作为参数的过程。

您可以在存储过程中的 SQL 语句中使用集合变量,例如 SELECT * FROM TABLE(collection_variable)

我也这样做了,但最大的挑战是使用 hibernate 从应用程序调用它 - I finally found the way to do that.

更新 可以从 Toad 运行的 SQL。

set serveroutput on; -- for debugging, 
-- it makes sense if your procedure outputs anything
declare my_list TableOfMyObject  := TableOfMyObject ();
begin 
  my_list.extend;
  my_list(1) := MyType([MyType constructor parameters]);

  my_list.extend;
  my_list(2) := MyType([MyType constructor parameters]);
  your_procedure(my_list);
end;

【讨论】:

  • 您能告诉我如何执行将 TableOfMyObject 作为 TOAD 或 SQL+ 参数的过程
  • @sandy :查看更新。该代码将 2 个元素放入集合并调用过程。
猜你喜欢
  • 1970-01-01
  • 2014-08-10
  • 1970-01-01
  • 2010-11-02
  • 2015-09-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-29
  • 1970-01-01
相关资源
最近更新 更多