Uploaded image for project: 'iBatis for .NET'
  1. iBatis for .NET
  2. IBATISNET-214

Conflict on session access with multiple DAO contexts

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • DataAccess 1.9 .1
    • DataAccess 1.9 .2
    • DataAccess
    • None

    Description

      If I have multiple DAO contexts defined and attempt to open or start a
      transaction on more than one context on the same thread I am receiving
      the "session already option / transaction already started" exception. I
      setup a test similar to the MultipleDAOTest in the iBATIS test cases
      like so:
      [Test]
      public void TestMultipleDAO()

      { DomDaoManagerBuilder builder = new DomDaoManagerBuilder(); builder.Configure("dao.config"); IDaoManager mgr1 = DaoManager.GetInstance("Context1"); IDaoManager mgr2 = DaoManager.GetInstance("Context2"); IPatronDAO pDao = mgr1[typeof(IPatronDAO)] as IPatronDAO; ILogDAO lDao = mgr2[typeof(ILogDAO)] as ILogDAO; mgr1.OpenConnection(); mgr2.OpenConnection(); <--- this is where the exception is thrown ... mgr1.CloseConnection(); mgr2.CloseConnection(); }

      I traced this into the iBATIS source, and see that when the
      DomDaoManagerBuilder creates a DaoManager instance
      (DaoManager.NewInstance), the internal DaoManager constructor is
      invoked, which immediately calls SessionStoreFactory with the DaoManager
      id to create a session store. The problem appears to be that the call
      to the SessionStoreFactory will always receive an empty string for id of
      the Dao Context, since DomDaoManagerBuilder::GetContexts() doesn't
      actually set the context id until after DaoManager.NewInstance()
      returns. As a result, sessions for all contexts on the same thread are
      keyed on the default string IBATIS_LOCAL_DAOSESSION from
      AbstractSessionStore, which I confirmed through VS2005 debugging. As
      soon as you create one session (openconnection or begintransaction), all
      contexts' LocalDaoSession reference this session because the sessionName
      is the same for all.

      Attachments

        Activity

          People

            gilles Gilles Bayon
            gilles Gilles Bayon
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: