将用户定义的列表从hibernate传递到oracle存储过程

时间:2012-12-20 13:23:30

标签: java oracle hibernate stored-procedures orm

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

班级如下。

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对象列表并将它们保存到表中。

1 个答案:

答案 0 :(得分:0)

  1. 创建OBJECT类型,在Oracle中说MyType is OBJECT ....,其中包含您需要的所有字段
  2. 创建集合类型TableOfMyObject IS TABLE OF MyObjectType
  3. 创建以TableOfMyObject为参数的过程。
  4. 您可以在存储过程中的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;