You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Joel Costigliola <jo...@steria.com> on 2006/02/08 11:26:12 UTC
Managing session opened with external connection
Hi all,
I would like to use iBatis on my project. I have some constraints :
- I need to use a connection management mecanism external to iBatis.
- I need to use a transactionnal mecanism external to iBatis (not EJB
but another one).
Following the javadoc example I have successfully inserted an object in
database but I'm wondering if the javadoc example is relevant for
releasing resources.
- do we have to close the session opened with an external connection ?
- if we close the session what will happen for the underlying
connection ?
is it closed ? (I would prefer not as connection is managed
externally !)
here's the code sample from the javadoc of SqlMapClient.openSession
(Connection)
try {
Connection connection = dataSource.getConnection();
SqlMapSession session = sqlMap.openSession(connection);
// do work
connection.commit();
} catch (SQLException e) {
try {
if (connection != null) commit.rollback();
} catch (SQLException ignored) {
// generally ignored
}
throw e; // rethrow the exception
} finally {
try {
if (connection != null) connection.close();
} catch (SQLException ignored) {
// generally ignored
}
}
by the way there is a typo mistake --> commit.rollback(); instead of
connection.rollback();
Thanks for your advices !
Joe