2011-02-23 4 views
0

Nhibernate 2.1.0.4000을 실행하는 .Net 3.5에서 작동하는 웹 사이트가 있습니다. 우리는 우리의 ProxyFactory로 spring을 사용하고있다.Nhibernate 2.1에서 Spring을 사용하면 .net 4가 throw됩니다. System.ExecutionEngineException이 발생합니다.

모두 정상적으로 작동합니다. 마법사를 사용하여 .Net 4.0으로 프로젝트를 업그레이드하려고했습니다. 모든 것이 순조롭게 진행되었습니다.

그러나 Nhibernate를 사용하여 코드를 작성하면 System.ExecutionEngineException 예외가 발생합니다. 스택 추적은없고 내부 예외는 없습니다.

우리는 NhibernateHelper 클래스 (아래)를 사용하고 있으며 이것으로 놀았으며 세션도 ok (예외 없음)로 구성됩니다. 세부 사항은 TEH .NET 3.5 버전

DB를 뭔가를 얻을 수있는 주먹 시도에서 어떤 변경 세션 요청 (아래 도시하지 않음)의 시작 핸들러에서 열립니다

실패 havn't는. 우리는 또한 Appliation 시작에 설정되어 통일성 사용하는

NHibernate에 대한 첫 번째 호출은

var emp = NHibernateHelper.CurrentSession.Get<SMS.DomainModel.Employee>(-200694); 

난 그냥 뭔가를 의미하고, 저를주는 오류 메시지를 원하는 것입니다 (확실하지를 그 어떤 관계가있는 경우) 계속할 일.

NhibernateProfiler를 살펴 보았습니다. 등록 된 것은 모두 세션의 시작입니다. 내가 NHProf에 대한 참조를 제거하여 유사한 문제를 해결할 수 있었다

using System; 
using System.Configuration; 
using System.IO; 
using System.Reflection; 
using FluentNHibernate; 
using FluentNHibernate.Cfg; 
using HibernatingRhinos.NHibernate.Profiler.Appender; 
using log4net; 
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration; 
using Microsoft.Practices.EnterpriseLibrary.Data.Configuration; 
using NHibernate; 
using NHibernate.Cfg; 
using NHibernate.Event; 
using NHibernate.Tool.hbm2ddl; 
using SMS.Infrastructure.Persistence.Logging; 
using SMS.Infrastructure.Persistence.Mappings; 
using Configuration=NHibernate.Cfg.Configuration; 
using System.Data.SqlClient; 

namespace SMS.Infrastructure.Persistence 
{ 
    public static class NHibernateHelper 
    { 
     static readonly ILog Log = LogManager.GetLogger(typeof(NHibernateHelper)); 
     static Configuration configuration; 

     public static ISessionFactory SessionFactory 
     { 
      get 
      { 
       return Singleton.sessionFactory; 
      } 
     } 

     // Lazy singleton pattern from http://www.yoda.arachsys.com/csharp/singleton.html 
     class Singleton 
     { 
      static Singleton() { } 

      internal static readonly ISessionFactory sessionFactory = CreateSessionFactory(); 
     } 

     public static ISession OpenSession() 
     { 
      return SessionFactory.OpenSession(); 
     } 

     public static ISession CurrentSession 
     { 
      get { return SessionFactory.GetCurrentSession(); } 
     } 

     static ISessionFactory CreateSessionFactory() 
     { 
      try 
      { 

       Log.Info("Creating NHibernate session factory"); 

       NHibernateProfiler.Initialize(); 

       configuration = new Configuration(); 

       try 
       { 
        // Try to configure NHibernate automagically... 
        configuration.Configure(); 
       } 
       catch (HibernateConfigException e) 
       { 
        if (e.InnerException is IOException) 
        { 
         // Otherwise specify a file name manually. 
         configuration.Configure("hibernate.cfg.xml"); 
        } 
        else 
         throw; 
       } 

       Log.Info("Registering custom SMS event listeners"); 

       RegisterCustomListeners(configuration); 

       // Has someone specified a default_schema? No? try and guess 
       // it from the (Enterprise Library :/) query string. 
       if (!configuration.Properties.ContainsKey("default_schema")) 
       { 
        Log.Info("Setting default schema"); 
        configuration.SetProperty("default_schema", GetDefaultSchema()); 
       } 

       ISessionFactory sessionFactory = Fluently.Configure(configuration) 
        .Mappings(m => 
        { 
         m.HbmMappings.AddFromAssemblyOf<BusinessUnitTypeMapping>(); 
         m.FluentMappings.AddFromAssemblyOf<BusinessUnitTypeMapping>(); 

        }) 
        .BuildSessionFactory(); 

       Log.Info("Session factory was configured successfully"); 

       return sessionFactory; 
      } 
      catch (Exception ex) 
      { 
       throw new ArgumentNullException(ex.ToString()); 
      } 
     } 

     /// <summary> 
     /// NHibernate allows custom event listeners to be registered in 
     /// config files or programmatically. Due to the re-use of configs in 
     /// SMS, we chose to do it via code. 
     /// 
     /// This is how we extend NHibernate for SMS, and this is why 
     /// NHibernate is the best ORM..! 
     /// </summary> 
     static void RegisterCustomListeners(Configuration config) 
     { 
      if (config == null) 
       throw new ArgumentNullException("config"); 

      // Event listeners for audit logging. 
      //config.SetListener(ListenerType.PreInsert, new AuditEventListener()); 
      //config.SetListener(ListenerType.PreUpdate, new AuditEventListener()); 
      //config.SetListener(ListenerType.PreDelete, new AuditEventListener()); 

      // Event listener for wiring up .NET events between parent/child 
      // objects, and the intermediary mapping for Tasks. 
      // 
      // Warning: be careful with the order in which these listeners are 
      // added!!! 
      // 
      // BindEventsOnLoadListener must come before 
      // TaskAddresseeLoadEventListener for example otherwise OSM Task 
      // Decorators don't attach properly. 
      config.SetListeners(ListenerType.PostLoad, new IPostLoadEventListener[] 
       { 
        new BindEventsOnLoadListener(), 
        new TaskAddresseeLoadEventListener() 
       }); 

     } 

     /// <summary> 
     /// Optional step: destroy and re-create the database scheme based on 
     /// the mapping files. Gives you a totally clean database in between 
     /// testing each fixture. 
     /// </summary> 
     public static void ExportDatabaseSchema(string fileName) 
     { 
      if (configuration == null) 
       CreateSessionFactory(); 

      Log.InfoFormat("Exporting DDL to {0}", fileName); 

      var exporter = new SchemaExport(configuration); 
      exporter.SetOutputFile(fileName); 
      exporter.Execute(true, false, false); 
     } 

     public static void ExportFluentMappings(string directoryName) 
     { 
      Log.InfoFormat("Exporting fluent mappings to {0}", directoryName); 
      var model = new PersistenceModel(); 
      model.AddMappingsFromAssembly(Assembly.GetAssembly(typeof(BusinessUnitTypeMapping))); 
      model.WriteMappingsTo(directoryName); 
     } 

     /// <summary> 
     /// hibernate's default_schema is worked out programmatically from the 
     /// Enterprise Library connection string. E.g. 
     /// Initial Catalog=OSM2Tests --> default_schema = SMS2Tests.dbo 
     /// </summary> 
     public static string GetDefaultSchema() 
     { 
      try 
      { 
       DatabaseSettings settings = DatabaseSettings.GetDatabaseSettings(new SystemConfigurationSource()); 
       var connectionstring = ConfigurationManager.ConnectionStrings[settings.DefaultDatabase].ConnectionString; 
       var initialCatalog = new SqlConnectionStringBuilder(connectionstring).InitialCatalog; 
       return String.Format("{0}.dbo", initialCatalog); 
      } 
      catch (Exception) 
      { 
       throw new Exception("Could not get default schema from connection string."); 
      } 
     } 
    } 
} 
+0

중요성이 있다면 Unity는 버전 1.2입니다. –

+0

hrmmm ... 흥미로운 질문 – Scozzard

답변

2

을 다음과 같이

어떤 도움이 많이

을 감사 NhibernateHelper 클래스입니다.

+0

이것은 나를 위해 생명의 은인과 비슷한 매우 비슷한 문제를 수정했습니다. 라이브러리를 업데이트하려고합니다. 고마워. – Ernesto