Skip to content

commit(true) leaks Statements/cursors when using connectionPool #202

@mbknor

Description

@mbknor

sql2o 1.5.2 and 1.5.4

If using beginTransaction and createQuery without explicit closing, commit with closeConnection=true will leak statements when using pooled connections.

I'm using Oracle and get "ORA-01000: maximum open cursors exceeded"

The problem is that Connection.commit(true) uses closeJdbcConnection() instead of close() which would have closed Statements before closing connection.

Example:

  def insertPersistentReprList(dtoList: Seq[JournalEntryDto]) {

    val sql = "insert into ...."

    // Insert the whole list in one transaction
    val c = sql2o.beginTransaction()
    try {

      dtoList.foreach {
        dto =>
          val insert = c.createQuery(sql)
          try {

            insert.addParameter("field", "value").executeUpdate

          } finally {
            // Without this statement-close, we would leak statements resulting in ORA-01000: maximum open cursors exceeded
            insert.close()
          }
      }

      // All inserts executed - commit transaction
      c.commit(true)
    } catch {
      case e:Throwable =>
        c.rollback(true)
        throw e
    }

  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions