C# mvc2 nhibernate问题

发布于 2024-09-29 21:13:23 字数 4843 浏览 1 评论 0原文

我的应用程序中有以下映射。映射是由自定义工具生成的。生成的其他映射工作正常,但这个映射给了我一个我不明白的奇怪错误。

这就是映射;

<?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>

这是当我尝试打开包含映射文件的网站时在浏览器中遇到的错误; Mapping Error

其堆栈跟踪如下;

[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>

I've got the following mapping in my application. The mapping is generated, by a custom tool. Other mappings generated work ok, but this one is giving me a strange error which I don't understand.

This is the mapping;

<?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>

This is the error which i'm getting in the browser when i trying to open the website containing the mapping file;
Mapping Error

The stacktrace with it is as below;

[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

I think the import thing to notice is that the exception i'm getting is an mapping exception as shown with this rule;

MappingException: Could not compile the mapping document: Plugin.Twitter.Business.Entities.Hbm.Tweet.hbm.xml]

I don't understand how and why though so I hope someone can tell me what the error means and how I can fix this issue. I've got the mapping marked as embedded resource.

UPDATE:
We're using the following hibernate.cfg.xml file in the application.

<?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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟雨凡馨 2024-10-06 21:13:23

这和你的映射关系不大。

它说:“在配置中找不到方言”,所以机会很大,您没有在配置中指定方言...

编辑:只要它们的 PK 生成是“本机”或,映射就可以在没有方言的情况下正常工作“顺序”。此映射使用需要方言的“guid”。

但是,您应该始终设置方言属性以获得其他配置属性的正确默认值(无需手动指定它们)...

This has little to do with your mapping.

It says: "Could not find the dialect in the configuration", so chances are big, you are not specifying a dialect in your configuration...

EDIT: Mappings work fine without a dialect as long as their PK generation is "native" or "sequence". This mapping is using "guid" wich requires a dialect.

But, you should always set the dialect property to get correct defaults for other configuration properties (without having to specify them manually)...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文