简体   繁体   English

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

[英]Passing user defined list from hibernate to oracle stored procedure

I want to pass a user defined object from my hibernate class and pass it onto a stored procedure which reads this list of objects and does the processing. 我想从休眠类中传递用户定义的对象,并将其传递到存储过程中,该存储过程将读取该对象列表并进行处理。 How can i do the same? 我该怎么做?

The Class is as follows. 该类如下。

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;
}

Can any one please let me know how to draft the procedure and how to loop through the list of ExcelListenerBean objects and save them to a table. 任何人都可以让我知道如何起草该过程以及如何遍历ExcelListenerBean对象列表并将其保存到表中。

  1. Create OBJECT type , say MyType is OBJECT .... in Oracle that has all the fields you need 在Oracle中创建OBJECT类型,比如说MyType is OBJECT .... ,它具有您需要的所有字段
  2. Create collection type , TableOfMyObject IS TABLE OF MyObjectType 创建集合类型, TableOfMyObject IS TABLE OF MyObjectType
  3. Create procedure that takes TableOfMyObject as parameter. 创建将TableOfMyObject作为参数的过程。

You can use collection variable in SQL statements in your stored procedure like SELECT * FROM TABLE(collection_variable) 您可以在存储过程的SQL语句中使用集合变量,例如SELECT * FROM TABLE(collection_variable)

I did the same, but the biggest challenge wast to call it from the app using hibernate - I finally found the way to do that. 我做了同样的事情,但是最大的挑战不是使用休眠模式从应用程序中调用它- 我终于找到了实现此目标的方法。

Update SQL that can be run from Toad. 更新可以从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;

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

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