似乎无法使 nhibernate 与 mysql 一起工作

本文关键字:mysql 一起 工作 nhibernate | 更新日期: 2023-09-27 18:34:09

我在设置 NHibernate 以使用 mysql 数据库时遇到问题.....错误:

[无效程序异常:JIT 编译器遇到内部限制。 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, IDictionary 2 inheritedMetas) +1901 NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(HbmClass rootClass, IDictionary 2 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: 无法编译映射文档: WebGest.NET.DomainModel.Mappings.XML.Operator.hbm.xml] NHibernate.Cfg.Configuration.LogAndThrow(异常异常( +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(字符串路径,程序集程序集( +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:'WebGest.NET.DomainModel.NHSession' 的类型初始值设定项抛出了一个异常。 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

网络配置:

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

映射文件:

   <?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() { }
       }
   }

那我做错了什么呢?

此外,asp.net 站点位于与包含 NHibernate 和 mysql 引用的"域模型"项目不同的项目中,这两个项目位于同一解决方案中。

似乎无法使 nhibernate 与 mysql 一起工作

尝试揭示异常的内部异常:

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

会有明确的信息,清晰的信息。例如:

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

这意味着未加载具有类 Operator 的项目。如果Operator未在域模型程序集中定义,则确实如此...

但我在这里猜测..内部异常会清楚地通知您...

好的,

显然问题是我的视觉工作室(我使用的是最新版本(,更具体的智能跟踪导致了问题,禁用智能跟踪将解决此问题。