title: JDBC Call to Oracle Stored Function - IN parameter of type "table of struct"
body: <p>I have a complex PL/SQL stored function and I have to call this function in JAVA.
  Here is the procedure : </p>
  
  <pre><code>FUNCTION SUB_REPORT_INCOMPLETE(p_ACT_ID IN ACTIVITIES.ID%TYPE,
                                 p_MISSING TO_SUB_MISSING) RETURN VARCHAR2;
  </code></pre>
  
  <p>So, as you can see here, the type of my second parameter is <strong>TO_SUB_MISSING</strong> which is  a table of <strong>O_SUB_MISSING</strong> : </p>
  
  <pre><code>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);
  </code></pre>
  
  <p>After some researchs, I write this code : </p>
  
  <pre><code>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();
  </code></pre>
  
  <p>But with this code I get an exception on the <em>StructDescriptor.createDescriptor</em> line : </p>
  
  <pre><code>java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to oracle.jdbc.OracleConnection
  </code></pre>
  
  <p>I try to solve this exception with two solutions I find on some <em>stackoverflow</em> post but it didn't work.</p>
  
  <p><strong>Solution 1 :</strong> </p>
  
  <pre><code>    OracleConnection oraConn = (OracleConnection) new DelegatingConnection(connection).getInnermostDelegate();
  </code></pre>
  
  <p><strong>Solution 2 :</strong> </p>
  
  <pre><code>    OracleConnection oraConn = connection.unwrap(OracleConnection.class);
  </code></pre>
  
  <p>The first solution throw the same exception and the second throw the following exception : </p>
  
  <pre><code>java.lang.AbstractMethodError: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.unwrap(Ljava/lang/Class;)Ljava/lang/Object;
  </code></pre>
  
  <p>Have you an idea of how I can solve my issue ?</p>