The other reason that the DataSourceUtils isn't used is because it will close a connection after a transaction completes:
Code:
public void afterCompletion(int status) {
// If we haven't closed the Connection in beforeCompletion,
// close it now. The holder might have been used for other
// cleanup in the meantime, for example by a Hibernate Session.
if (this.holderActive) {
// The thread-bound ConnectionHolder might not be available anymore,
// since afterCompletion might get called from a different thread.
if (TransactionSynchronizationManager.hasResource(this.dataSource)) {
TransactionSynchronizationManager.unbindResource(this.dataSource);
}
this.holderActive = false;
if (this.connectionHolder.hasConnection()) {
releaseConnection(this.connectionHolder.getConnection(), this.dataSource);
// Reset the ConnectionHolder: It might remain bound to the thread.
this.connectionHolder.setConnection(null);
}
this.connectionHolder.reset();
}
}
See the TransactionSyncrhonization method for more information on afterCompletion.