Denis Susan
Denis Susan

Reputation: 35

Cannot seem to make nhibernate work with mysql

I have a problem setting up NHibernate to work with a mysql database..... error:

[InvalidProgramException: JIT Compiler encountered an internal limitation.] NHibernate.Cfg.MappingSchema.HbmId.get_Type() +0 NHibernate.Cfg.XmlHbmBinding.ClassIdBinder.BindId(HbmId idSchema, PersistentClass rootClass, Table table) +477 NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(HbmClass classSchema, IDictionary2 inheritedMetas) +1901 NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(HbmClass rootClass, IDictionary2 inheritedMetas) +295 NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddEntitiesMappings(HbmMapping mappingSchema, IDictionary`2 inheritedMetas) +321 NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(HbmMapping mappingSchema) +316 NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName) +489

[MappingException: Could not compile the mapping document: WebGest.NET.DomainModel.Mappings.XML.Operator.hbm.xml] NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) +220 NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName) +741 NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) +233 NHibernate.Cfg.Configuration.ProcessMappingsQueue() +121 NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document) +195 NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name) +217 NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) +284 NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) +483 NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) +459 NHibernate.Cfg.Configuration.AddAssembly(String assemblyName) +410 NHibernate.Cfg.Configuration.DoConfigure(ISessionFactoryConfiguration factoryConfiguration) +1935 NHibernate.Cfg.Configuration.Configure() +269 WebGest.NET.DomainModel.NHSessionFactory.Init() in e:\dev\C#\WebGest.net\webgest\WebGest.NET\DomainModel\NHSessionFactory.cs:21 WebGest.NET.DomainModel.NHSessionFactory.GetSessionFactory() in e:\dev\C#\WebGest.net\webgest\WebGest.NET\DomainModel\NHSessionFactory.cs:32 WebGest.NET.DomainModel.NHSessionFactory.get_Instance() in e:\dev\C#\WebGest.net\webgest\WebGest.NET\DomainModel\NHSessionFactory.cs:45 WebGest.NET.DomainModel.NHSession..cctor() in e:\dev\C#\WebGest.net\webgest\WebGest.NET\DomainModel\NHSession.cs:12

[TypeInitializationException: The type initializer for 'WebGest.NET.DomainModel.NHSession' threw an exception.] WebGest.NET.Login.Page_Load(Object sender, EventArgs e) in e:\dev\C#\WebGest.net\webgest\WebGest.NET\WebGest.NET\Login.aspx.cs:16 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +188 System.EventHandler.Invoke(Object sender, EventArgs e) +0 System.Web.UI.Control.OnLoad(EventArgs e) +162 System.Web.UI.Control.LoadRecursive() +164 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3601

Web.config:

 <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
     <reflection-optimizer use="false" />
     <session-factory>
       <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
       <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
       <property name="connection.connection_string">Server=localhost;Database=webgest;User ID=root;Password=;</property>
       <property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
       <mapping assembly="DomainModel" />
     </session-factory>
   </hibernate-configuration>

Mapping file:

   <?xml version="1.0" encoding="utf-8" ?>
   <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" 
   namespace="WebGest.NET.DomainModel"
   assembly="DomainModel">
     <class name="Operator" table="s_operatori">

       <id name="IdOperator" column="IdOperator" unsaved-value="0">
         <generator class="native" />
       </id>

       <property name="User">
         <column name="User" not-null="true" />
       </property>

       <property name="Parola">
         <column name="Parola" not-null="false" />
       </property>

       <property name="FlagActiv">
         <column name="FlagActiv" not-null="true" />
       </property>
     </class>
   </hibernate-mapping>

CS:

   namespace WebGest.NET.DomainModel
   {
       public partial class Operator
       {
           public virtual int IdOperator { get; set; }
           public virtual string User { get; set; }
           public virtual string Parola { get; set; }
           public virtual bool FlagActiv { get; set; }
           public Operator() { }
       }
   }

So what am I doing wrong?

Also the asp.net site is in a separate project from the "domainmodel" project containing NHibernate and mysql references, both projects are in the same solution.

Upvotes: 0

Views: 181

Answers (2)

Denis Susan
Denis Susan

Reputation: 35

Ok so apparently the problem was my visual studio (i'm using the latest version), more specific intelitrace was causing the problem, disabling intelitrace will fix this.

Upvotes: 0

Radim K&#246;hler
Radim K&#246;hler

Reputation: 123861

Try to reveal the inner exception of the Exception:

{"Could not compile the mapping document: WebGest.NET.DomainModel.Mappings.XML.Operator.hbm.xml"}

There will be clear information, clear message. For example:

{"persistent class WebGest.NET.DomainModel.Operator, DomainModel not found"}

Which would mean, that the project with class Operator was not loaded. That would be true, if the Operator is not defined in the DomainModel assembly...

But I am guessing here.. The inner exception will clearly inform you...

Upvotes: 1

Related Questions