Announcement Announcement Module
Collapse
No announcement yet.
how to call Oracle stored function fro Spring JPA DAO Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to call Oracle stored function fro Spring JPA DAO

    I need to call an Oracle stored procedure function within a spring JPA DAO class. I thought of obtaining Connection from Spring JPA template and execute the stored function. Now function is getting called. But it seems the connection is not geting close properly. i.e. There is a server error saying connection is not properly closed, every time I call this stored function. Can anyone help me isolate the issue. Is there a better way to call stored function within Spring JPA other than my code as folllows.

    try {
    ConnectionHandle connHandle = null;
    Connection conn = null;

    JpaTemplate jpaTemplate = getJpaTemplate();
    EntityManagerFactory entityManagerFactory = jpaTemplate
    .getEntityManagerFactory();
    EntityManager entityManager = entityManagerFactory
    .createEntityManager();

    ConnectionHandle connectionHandle = getJpaTemplate().getJpaDialect()
    .getJdbcConnection(entityManager, false);

    conn = connHandle.getConnection();
    cStmt = conn.prepareCall({? = call DCS_PKG_FLIGHT_SCHEDULE.dcs_f_flight_schedule_canc el(?) });
    cStmt.setString(C_SCHEDULE_IDS, scheduleIds);
    cStmt.registerOutParameter(C_RETURN_STATE, Types.VARCHAR);
    cStmt.execute();

    returnObj = cStmt.getString(C_RETURN_STATE);

    }catch (...)
    ..
    }finally (

    if (cStmt != null) {
    try {
    cStmt.close();
    } catch (Exception cStmtExc) {
    log.error("Exception occurred when closing the callable statement." + cStmtExc.getMessage());
    }
    }

    if (conn != null) {
    try {
    conn.close();
    } catch (Exception connExc) {
    log.error("Exception occurred when closing the connection." + connExc.getMessage());
    }
    }


    }
Working...
X