Oracle does not close the cursors opened by JPA query even after EntityManager.close() is called

1k Views Asked by At

I am using JPA, hibernate and Oracle DB. While calling method findAll(..) multiple times (say 1000), each time Oracle opens a new cursor. The opened cursor is not closed after entity manager transaction is committed or entityManager is closed (lem.close()). Problem is that oracle opens 1000 cursors and reaches maximum open cursor limit and throw error ORA-01000: maximum open cursors exceeded. How can I force oracle to close the opened cursors?

public List<T> findAll(Long id1, Long id2, Long id3, boolean cacheResults) {
    EntityManager lem = emf.createEntityManager();
    lem.getTransaction().begin();
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    List<T> listRowValue = lem.createNativeQuery("select * from MASTER b where id = " + id1 + " and id = " + id2 + " and id = " + id3)
            .getResultList();
    lem.getTransaction().commit();
    lem.close();
    return listRowValue;
}
0

There are 0 best solutions below