Uploaded image for project: 'Spring.NET'
  1. Spring.NET
  2. SPRNET-779

NHibernateTransactionManager can not convert AdoAcessException

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 1.1 RC2
    • Fix Version/s: 1.1.0
    • Labels:
      None
    • Environment:
      Windows XP SP2, Sql Server 2005

      Description

      When you use OpenSessionInView module in a web application and use HibernateTransactionManager, you get "NullReferenceException" in response to a AdoException at "HibernateTransactionManager.ConvertAdoAccessException" method. The code i tried is as follows:

      This is the dao method,

      [Transaction(ReadOnly = false)]
      public void Save(Product product)
      {
      this.HibernateTemplate.Save(product);
      }

      I have copied the configuration from the Spring.Data.NHibernate.Northwind project in examples folder.

      I checked the source files and I think that, because there is an existing transaction HibernateTemplate does not flush the session. So the exception is not thrown from HibernateTemplate. At the end of the transaction, HibernateTransactionManager tries to commit the transaction and NullReferenceException occurs because "adoExceptionTranslator" field of the transaction manager is null. The documentation does not tell about how to set an AdoExceptionTranslator to this field. I think the main problem is that, if you use HibernateTransactionManager, HibernateTemplate's error handling becomes useless.

      I changed the getter of "AdoExceptionTranslator" in "HibernateTransactionManager" as the following,

      public IAdoExceptionTranslator AdoExceptionTranslator
      {
      set

      { adoExceptionTranslator = value; }

      get
      {
      if (adoExceptionTranslator == null)

      { adoExceptionTranslator = SessionFactoryUtils.NewAdoExceptionTranslator(SessionFactory); }

      return adoExceptionTranslator;
      }
      }

      which i copied from HibernateTemplate. Now the AdoException is being converted.

        Attachments

          Activity

            People

            • Assignee:
              mark.pollack Mark Pollack
              Reporter:
              ckalan cagatay kalan
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: