2013-07-08 8 views
5

Ho una complessa funzione memorizzata PL/SQL e devo chiamare questa funzione in JAVA. Ecco la procedura:JDBC Chiamata a Oracle Stored Function - Parametro IN di tipo "table of struct"

FUNCTION SUB_REPORT_INCOMPLETE(p_ACT_ID IN ACTIVITIES.ID%TYPE, 
           p_MISSING TO_SUB_MISSING) RETURN VARCHAR2; 

Quindi, come si può vedere qui, il tipo del mio secondo parametro è TO_SUB_MISSING che è un tavolo di O_SUB_MISSING:

CREATE OR REPLACE TYPE TO_SUB_MISSING AS TABLE OF O_SUB_MISSING; 
CREATE OR REPLACE TYPE O_SUB_MISSING AS OBJECT (ACT_ID NUMBER, GIT_ID NUMBER, MISSING_QTY NUMBER); 

Dopo alcuni Ricerche da , Scrivo questo codice:

Context context = new InitialContext(); 
DataSource dataSource = (DataSource) context.lookup(dataSourceName); 
connection = dataSource.getConnection(); 

StructDescriptor structDescriptor = StructDescriptor.createDescriptor("O_SUB_MISSING", connection); 
STRUCT[] structs = new STRUCT[listPieces.size()]; 
int ind = 0; 
for (PieceEntity piece : listPieces) { 
    Object[] params = new Object[3]; 
    params[0] = piece.getActId(); 
    params[1] = piece.getGitId(); 
    params[2] = piece.getMissingQty(); 
    STRUCT struct = new STRUCT(structDescriptor, connection, params); 
    structs[ind++] = struct; 
} 
ArrayDescriptor desc = ArrayDescriptor.createDescriptor("TO_SUB_MISSING", connection); 

statement = connection.prepareCall(Constants.DECLARE_INCOMPLETE_MODUL); 
statement.registerOutParameter(1, OracleTypes.VARCHAR); 
statement.setLong(2, agmId); 
statement.setArray(3, new ARRAY(desc, connection, structs)); 
statement.executeQuery(); 

Ma con questo codice I g et un'eccezione sulla StructDescriptor.createDescriptor linea:

java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to oracle.jdbc.OracleConnection 

ho cercare di risolvere questa eccezione con due soluzioni che trovo su alcuni StackOverflow post, ma non ha funzionato.

Soluzione 1:

OracleConnection oraConn = (OracleConnection) new DelegatingConnection(connection).getInnermostDelegate(); 

Soluzione 2:

OracleConnection oraConn = connection.unwrap(OracleConnection.class); 

La prima soluzione gettare la stessa eccezione e il secondo lancio la seguente eccezione:

java.lang.AbstractMethodError: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.unwrap(Ljava/lang/Class;)Ljava/lang/Object; 

Hai un'idea di come posso risolvere il mio problema?

+1

Per la soluzione 1 è stato impostato 'accessToUnderlyingConnectionAllowed =" true "' nel contesto di configurazione? –

+0

ho provo ad aggiungere THS nel context.xml del mio server Tomcat: ' accessToUnderlyingConnectionAllowed vero ' Ma non ha cambiato nulla. – Mikael

risposta

Problemi correlati