我的应用程序中有以下映射。映射由自定义工具生成。生成的其他映射工作正常,但是这个给我一个奇怪的错误,我不明白。
这是映射;
<?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>
答案 0 :(得分:2)
这与您的映射几乎没有关系。
它说:“无法在配置中找到方言”,所以机会很大,你没有在配置中指定方言......
编辑:只要他们的PK生成是“本机”或“序列”,映射就可以在没有方言的情况下正常工作。这种映射使用的是“guid”,需要一种方言。但是,您应该始终设置dialect属性以获取其他配置属性的正确默认值(无需手动指定)...