1
我的應用程序中有以下映射。該映射是由自定義工具生成的。其他映射生成工作正常,但這是給我一個奇怪的錯誤,我不明白。C#mvc2 nhibernate問題
這是映射;
<?xml version="1.0" encoding="utf-8"?>
<!--Generated by NHibernate.Mapping.Attributes on 2010-10-29 08:39:48Z.-->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Plugin.Twitter.Business.Entities.Tweet, Plugin.Twitter" table="PluginTwitter_Tweet">
<id name="Id" column="Id">
<generator class="guid" />
</id>
<property name="TweetMessage" />
<property name="TweetDate" />
<property name="TweetId" />
</class>
</hibernate-mapping>
這是我在瀏覽器中獲取的錯誤,當我試圖打開包含映射文件的網站時;
帶它的堆棧跟蹤如下;
[InvalidOperationException: Could not find the dialect in the configuration]
NHibernate.Dialect.Dialect.GetDialect(IDictionary 2 props) +204
NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) +155
[MappingException: Could not compile the mapping document: Plugin.Twitter.Business.Entities.Hbm.Tweet.hbm.xml]
NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) +534
NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) +378
NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) +419
NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) +355
NHibernate.Cfg.Configuration.AddAssembly(String assemblyName) +291
CMS.ResourceAccess.DataAccessLogic.SessionManagement.SessionManager..ctor() in C:\Projects\Website\Website.ResourceAccess\DataAccessLogic\SessionManagement\SessionManager.cs:73
Website.ResourceAccess.DataAccessLogic.SessionManagement.NestedSessionManager..cctor() in C:\Projects\Website\Website.ResourceAccess\DataAccessLogic\SessionManagement\SessionManager.cs:90
[TypeInitializationException: The type initializer for 'NestedSessionManager' threw an exception.]
Website.ResourceAccess.DataAccessLogic.SessionManagement.SessionManager.get_Instance() in C:\Projects\Website\Website.ResourceAccess\DataAccessLogic\SessionManagement\SessionManager.cs:39
CMS.ResourceAccess.DataAccessLogic.SessionManagement.SessionManager.get_SessionFactory() in C:\Projects\Website\Website.ResourceAccess\DataAccessLogic\SessionManagement\SessionManager.cs:23
Website.Backend.MvcApplication.StartNHibernateSession() in C:\Projects\Website\Website.Web\Global.asax.cs:82
Website.Backend.MvcApplication.Application_Start() in C:\Projects\Website\Website.Web\Global.asax.cs:47
[HttpException (0x80004005): The type initializer for 'NestedSessionManager' threw an exception.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +3988565
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +191
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +325
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375
[HttpException (0x80004005): The type initializer for 'NestedSessionManager' threw an exception.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11529072
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4784373
我認爲需要注意的是我得到的異常是一個映射異常,如該規則所示;
MappingException: Could not compile the mapping document: Plugin.Twitter.Business.Entities.Hbm.Tweet.hbm.xml]
我不明白如何以及爲什麼雖然所以我希望有人能告訴我什麼是錯誤的手段,我怎麼能解決這個問題。我有映射標記爲嵌入式資源。
更新: 我們在應用程序中使用以下hibernate.cfg.xml文件。
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns='urn:nhibernate-configuration-2.2'>
<session-factory>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string_name">NHibernate</property>
<property name="current_session_context_class">managed_web</property>
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
<!--Needed for NH Profiler-->
<property name="generate_statistics">false</property>
</session-factory>
</hibernate-configuration>
在你的意思是在web.config?好吧..但是,如果我從項目中刪除了所提到的映射,那麼應用程序如何按預期工作? – Rob 2010-10-29 07:06:00
嗯,這確實很奇怪......你的項目中還有其他映射嗎?根據你的堆棧跟蹤,當NHibernate運行它的配置時會發生錯誤(在第一次會話調用時發生)。你測試過沒有映射,所以它實際上通過NHibernate加載(其他)數據? – Bertvan 2010-10-29 07:16:30
無論如何,你的配置中是否有以下內容? <您的方言選擇> – Bertvan 2010-10-29 07:17:26