The behavior of c3p0 is the correct one,
the default pool behaviors not correctly and should not be used for production use.
Since you:
- are not in transaction
- have not configured hibernate.connection.release_mode explicitely
(so with JDBCTransactionFactory it defaults to ConnectionReleaseMode.AFTER_TRANSACTION )
- have hibernate.connection.autocommit set to true
as soon
Code:
session.get(Batch.class, Integer.valueOf(31066));
is executed, hibernate closes the current connection,
Quote:
ConnectionManager.closeConnection() line: 463
ConnectionManager.aggressiveRelease() line: 429
ConnectionManager.afterTransaction() line: 316
JDBCContext.afterNontransactionalQuery(boolean) line: 268
SessionImpl.afterOperation(boolean) line: 587
SessionImpl.get(String, Serializable) line: 1002
SessionImpl.get(Class, Serializable) line: 990
thus c3p0 closes all regarding resources and puts the connection back to the pool.
In this way also the open cursor is closed and for this reason in the next line
Code:
r.next();
you get java.sql.SQLException: Closed Resultset:
It's not happening with default pool because probably
the default pool against jdbc-spec don't closes all resources bound to the connection
(therefore there' is also a warning that the default pool should not be used for production use).
N.B.: If you set hibernate.connection.release_mode=on_close then your app. will work,
but same as Froeste I suggest you to use transaction boundaries begin and commit/rollback.