ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clinton Begin <clinton.be...@gmail.com>
Subject Re: iBATIS 3.0 with Spring and iBatisWorkShop AUTO-COMMIT and session close
Date Thu, 22 Apr 2010 04:18:55 GMT
It's highly unlikely that these are bugs in iBATIS.  We have lots of unit
tests that validate this functionality.  We've also had 10 straight months
of beta testing that have not yielded any problems.

One known issue is that ManagedTransactions are not being closed on some app
servers, but even that is fixed in the trunk and will be released.

Cheers,
Clinton

On Wed, Apr 21, 2010 at 10:03 PM, Dmitry Shirkalin <dmitry@peoplepowerco.com
> wrote:

>  Hi,
>
> We are using iBATIS 3.0 with Spring and iBatisWorkShop.
> We inherits our DAO classes from SqlSessionDaoSupport from iBatisWorkShop.
>
> I tried to use iBATIS SQL session like in the following code
>
>     SqlSession session = *null*;
>
> *    try* {
>         session = getSqlSessionFactory().openSession(ExecutorType.*REUSE*
> , *false*); // NOT auto-commit
>         MapperInterface mapper = session.getMapper(MapperInterface.*class*
> );
>         // do several interface method calls
>         ...
>         *session.commit();
> *    } *catch* (Exception e) {
> *        if* (session != *null*) *session.rollback();
> *    } *finally* {
> *        if* (session != *null*) *session.close()*;
>     }
>
> Here getSqlSessionFactory() is the method of SqlSessionDaoSupport, which
> returns DefaultSqlSessionFactory object.
>
> There are two issues with this code:
> 1) The JDBC connection associated with the SQL session has auto-commit
> equal true, even the openSession() method called with autoCommit equal
> false. So all statements are committed automatically.
> 2) The SqlSession.close() method does not close the database connection or
> return the connection to the connection pool. It happens because the
> openSession() method returns DefaultSqlSession object, which does not
> support this functionality.
>
> iBatisWorkShop uses the SqlSessionUtils.*closeSqlSession*(SqlSession,
> SqlSessionFactory) method to close SQL session and correctly return the
> database connection to the connection pool.
> An example below using this method works fine.
>
>     SqlSession session = *null*;
>     *boolean* autoCommit = *false*;
>     Connection conn = *null*;
>
>     *try* {
>         session = getSqlSessionFactory().openSession(ExecutorType.*REUSE*
> , *false*);
>         conn = session.getConnection();
>         autoCommit = conn.getAutoCommit();
>         conn.setAutoCommit(*false*);
>         ...
>         session.commit();
>     } *catch* (Exception e) {
>         *if* (session != *null*) session.rollback();
>     } *finally* {
>         *if* (conn != *null*) {
>             *try* {
>                 conn.setAutoCommit(autoCommit);
>             } *catch* (SQLException e) {
>             }
>         }
>         *if* (session != *null*) {
>             SqlSessionUtils.*closeSqlSession*(session,
> getSqlSessionFactory());
>         }
>     }
>
>
> So, are these two issues bugs in iBATIS or incomplete implementation of
> SqlSessionFactory in iBatisWorkShop?
>
>
> Thanks,
> Dmitry
>

Mime
View raw message