Hello, I have created a stored procedure and it works when executed in the DB.

 

Now I want to make a stored procedure call from Java using JPA 2.1 (either Toplink o Eclipselink). I make a test case but with no luck. All the time gives me Null as return value.

 

Test Case 1:

            DataReadQuery databaseQuery = new DataReadQuery();

            databaseQuery.setResultType(DataReadQuery.VALUE);

            PLSQLrecord record = new PLSQLrecord();

            record.setTypeName("EMP_PKG.EMP_REC"); //Name of the procedure

            record.setCompatibleType("EMP_TYPE");

            record.setJavaType(TUser.class);

            record.addField("nickname", JDBCTypes.VARCHAR_TYPE, 30);

            record.addField("email", JDBCTypes.VARCHAR_TYPE, 30);

            record.addField("identification", JDBCTypes.NUMERIC_TYPE, 10, 2);

            PLSQLStoredFunctionCall call = new PLSQLStoredFunctionCall(record);

            call.setProcedureName("EMP_PKG.GET_EMP");

            databaseQuery.setCall(call);

 

            Query query = ((JpaEntityManager) em.getDelegate()).createQuery(databaseQuery);

            TUser result = (TUser) query.getSingleResult();

 

            System.out.println("The result " + result.getNickname() + " " + result.getEmail() + " " + result.getIdentification());

 

This case only prints "null" for all the gets...

 

Test case 2:

            StoredProcedureQuery query2 = em.createStoredProcedureQuery("PRQ_SEQUENCE", Sequence.class);

            query2.registerStoredProcedureParameter("I_ID", String.class, ParameterMode.IN);

            query2.registerStoredProcedureParameter("SYS_REFCURSOR", void.class, ParameterMode.REF_CURSOR);

            query2.registerStoredProcedureParameter("O_OK", String.class, ParameterMode.OUT);

         

            boolean execute = query2.setParameter("I_ID", "T_USER").execute();         

            if (execute){

             

            }

            String ok = (String) query2.getOutputParameterValue("O_OK");

            System.out.println("OK value"+ ok);

            List<Sequence> sequence = (List<Sequence>) query2.getOutputParameterValue("SYS_REFCURSOR");

            for(Sequence seq : sequence) {

                 System.out.println(seq.getName());

            }

 

This case gives error at the first line with:

]] Root cause of ServletException.

java.lang.NoSuchMethodError: javax.persistence.EntityManager.createStoredProcedureQuery(Ljava/lang/String;[Ljava/lang/Class;)Ljavax/persistence/StoredProcedureQuery;

 

What is the way to call a procedure from java? or what is wrong with this cases?

 

Environment

Oracle DB 12c

Oracle Weblogic 12c

Java 1.7 + Netbeans

JPA 2.1, Eclipselink

javax.persistence-2.1.0.jar


Thanks!

FacebookTwitterLinkedin
Pin It
Joomla Tutorials for Beginners