The documentation module has a TransactionUtil class which offers automatic Session and transaction management. This way, it's much easier to make sure that connections don't leak.