views:

43

answers:

1

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>
+2  A: 

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)...

Bertvan
In the web.config you mean? Ok..but how is it possible then that the application works as expected when i remove the mentioned mapping from the project?
Rob
Hmm, that is indeed strange... Do you have other mappings in your project? According to your stack trace, the error happens when NHibernate is running its Configuration (wich happens on first session call). Have you tested without the mapping, so that it actually loads (other) data through NHibernate?
Bertvan
In any case, do you _have_ the following in your config? <property name="dialect">(Your Dialect of Choice)</property>
Bertvan
Also, the reason why this specific mapping isn't working without a dialect is the guid id generator. If your other mappings stick to guid or native ids, they should work fine without dialect...
Bertvan
@Bertvan I've updated the question with the nhibernate config which is being used in a seperate file.
Rob
@Bertvan yes I've tested without this specific mapping file. Then the application works as expected. No other errors occur in the application when i exclude Tweet.hbm.xml as the file i mentioned is called.
Rob
@Bertvan Other mappings in the application are using an joined-subclass. They're inhereting from other entities. I've got one other working mapping in the application which is similar to this one. And that one is working fine. The id column is of the type uniqueidentifier in the sql2008 database. This because where storing guid's as unique id in the pk column
Rob
Are you sure the config in the separate file is being used? Everything points to a missing dialect property... Afaik, NHibernate reads the .cfg from the bin folder, maybe that .cfg isn't up to date?
Bertvan
I've checked the .cfg in the bin folder. It's up-to-date and looks equal to the one in the solution. Same for the .dll of the project. I've now commented out all the mapping properties except the id and the problem still persists.
Rob
Ok, next thing to check: What version of NHibernate are you using. And can you try to change the dialect to NHibernate.Dialect.MsSql2005Dialect ? So 2005 in stead of 2008?
Bertvan
Nhibernate version is version 2. But i think i just found a solution which i'm testing right now..
Rob
MsSql2008Dialect isn't available in NH 2, it's only available from NH 2.1 => If you'll use 2005 dialect it should work, or upgrade to NH 2.1 (http://216.121.112.228/browse/NH-1571)
Bertvan
@Bertvan. I mentioned earlier that i was using nhibernate.cfg.xml as an external config file. While testing i moved the configuration from this file to the web.config of the application itself (using this example > http://www.davesquared.net/2008/08/configuration-changes-in-nhibernate-20.html) After moving this everything worked :-D. Don't know how or why, for some reason nhibernate indeed didn't seem to be able to find the dialect property.+1 For the good help and pointing me in the right direction
Rob
@Bertvan. My bad, we use 2.1.2.4000
Rob