StoredProcedure Call from JPA

Asked 2 years ago, Updated 2 years ago, 111 views

For multiple requests, JPA's StoredProcedureQuery implements the process of making procedural calls and registering them.
I want to reflect everything only if it is successful, so I make it a start at the beginning of the process and commit when it is finished.
The database is Oracle.

The problem is that each time I repeatedly call the execute method in StoredProcedureQuery, the cursor was opened, and when I reached 300, the ora-01000 (maximum number of open cursors exceeded) failed.
By the way, emptying the processing in the procedure resulted in the same error, so the procedure call itself probably created the cursor.

Please let me know if there is a solution.The Java code is as follows:

// Java code

try{
    fac=Persistence.createEntityManagerFactory("xxx");
    em = fac.createEntityManager();
    tx = em.getTransaction();

    StoredProcedureQuery spq;
    spq = em.createStoredProcedureQuery("yyyy";
    spq.registerStoredProcedureParameter(1,Object.class,ParameterMode.IN);
    spq.registerStoredProcedureParameter(2,Object.class,ParameterMode.IN);
    spq.registerStoredProcedureParameter(3,Short.class,ParameterMode.OUT);
    spq.registerStoredProcedureParameter(4,Short.class,ParameterMode.OUT);
    tx.begin(); 

    for(List<String>rec:csv){
        String aaa = rec.get(0);
        String bb = rec.get(1);
        spq.setParameter(1,aa);
        spq.setParameter(2,bb);
        // execution
        spq.execute();

        // error checking
        if(...){
            tx.rollback();
            return;
        }
    }
    tx.commit();
}catch(Exceptione){
    through;
}finally {
    if(em!=null)em.close();
    if(fac!=null)fac.close();
}

java jpa

2022-09-30 18:25

1 Answers

close() processing of EntityManager is not implemented.For example, em.close(); is not called finally in the following implementations:

try{
    StoredProcedureQuery StoredProcedureQuery
            = em.createStoredProcedureQuery("XXXX", Test.class);
    storedProcedureQuery.execute();
    return storedProcedureQuery.getResultList();
} catch(Exceptione){
    e.printStacktrace();
} US>finally
    em.close();
}


2022-09-30 18:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.