2012-10-11 22 views
0

從Oracle到Java獲取複雜對象類型時遇到困難。使用Spring JDBCTemplate和StoredProcedure API從Spring中的存儲過程中獲取複雜用戶定義的SQL類型

我正在使用Spring JDBCTemplate和Spring StoredProcedure。

在我已經使用其返​​回對象(單位)的函數在Oracle端包含物件(除法)的表(DIVISION_TAB),其本身由另一個對象(EMPLOYEE)的一個表(EMPLOYEE_TAB)組成。

這些類型的定義如下:在數據庫級

create or replace TYPE UNIT AS OBJECT 
( 
    UNIT_ID  NUMBER(38), 
    UNIT_NAME  VARCHAR(50), 
    DIVIVSION_LIST DIVIVSION_TAB 
) 

create or replace 
TYPE DIVISION_TAB 
AS TABLE OF DIVISION 

create or replace 
TYPE DIVISION AS OBJECT 
( 
    DIV_ID  NUMBER(38), 
    DIV_NAME  VARCHAR(50), 
    DIV_STATUS NUMBER(38), 
    EMPLOYEE_LIST EMPLOYEE_TAB 
) 

create or replace 
TYPE EMPLOYEE_TAB 
AS TABLE OF EMPLOYEE 

create or replace 
    TYPE EMPLOYEE AS OBJECT 
    ( 
     EMP_ID  NUMBER(38), 
     EMP_NAME  VARCHAR(50), 
     EMP_STATUS NUMBER(38), 
     EMP_SAL  NUMBER(20), 
    ) 

函數返回ME單元的SQL對象,而在Java中取回我使用下列方式其中。

declareParameter(new SqlOutParameter("UNIT", OracleTypes.STRUCT, "UNIT",new SqlReturnType() { 
     public Object getTypeValue(CallableStatement callableStatement, int colIndx, int sqlType, String typeName) 
      throws SQLException { 
     Connection connection = callableStatement.getConnection(); 

     Map<String, Class<?>> typeMap = connection.getTypeMap(); 
     typeMap.put("UNIT", Unit.class); 
     typeMap.put("DIVISION_TAB", java.sql.Array.class); 
     typeMap.put("DIVISION", Division.class); 
     typeMap.put("EMPLOYEE_TAB", java.sql.Array.class); 
     typeMap.put("EMPLOYEE", Employee.class); 

     STRUCT struct = (STRUCT)callableStatement.getObject(colIndx); 
     Object[] attr = struct.getAttributes(); 
     return attr; 
     } 
    })); 

問題::::

當我調試對象[]通過SqlReturnType類(返回)方法然後我能夠取像UNIT_ID和UNIT_NAME的細節,而是在第三屬性即類型的Oracle的.sql.ARRAY,當我執行以下操作時:

 ARRAY array = (ARRAY)attr[3]; 
    Object[] objects = (Object[])((ARRAY)attr[3]).getArray(); 

它引發SQL Internat異常。

回答

0

此問題已解決。只是一個簡單的錯誤。代碼完全正確,我錯過了授予我定義的類型的授權。

相關問題