开发者

MappingException was unhandled: NHibernate

开发者 https://www.devze.com 2023-02-19 11:37 出处:网络
I am trying to learn about NHibernate from the book NHibernate in Action and trying to compile and run the first example is giving me the following exception:

I am trying to learn about NHibernate from the book NHibernate in Action and trying to compile and run the first example is giving me the following exception:

Could not compile the mapping document:

Namespace.FolderName.ClassName.hbm.xml

The inner exception is

{"<hibernate-mapping xmlns='urn:hibernate-mapping-2.2'> was not expected."}

Here's my mapping file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:hibernate-mapping-2.2"
                   auto-import="true">
  <class name="Namespace.Folder.ClassName,Namespace.Folder" lazy="false">
    <id name="id" access="field">
      <generator class="native" />
    </id>
    <property name="name" access="field" column="name"/>
    <many-to-one access="field" name="manager" column="manager"
                 cascade="all"/>
    </class>
</hibernate-mapping>

This happens when I am trying to create a session as follows:

static ISession OpenSession()
        {
            if (factory == null)
            {
                Configuration c = new Configuration();
                c.AddAssembly(Assembly.GetCallingAssembly());
                factory = c.BuildSessionFactory();
            }
            return factory.OpenSession();
        }

The exception is raised by the following line:

c.AddAssembly(Assembly.GetCallingAssembly());

Here's the entire exception stack trace:

**

NHibernate.MappingException was unhandled Message=Could not compile the mapping document: DataGenerator.HibernateMapper.Individual.hbm.xml Source=NHibernate StackTrace: at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 340 at NHibernate.Cfg.Configuration.LoadMappingDocument(XmlReader hbmReader, String name) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1783 at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1813 at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 630 at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 668 at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 761 at DataGenerator.Program.OpenSession() in C:\Documents and Settings\user1\Desktop\DataGeneration\DataGenerator\DataGenerator\Program.cs:line 46 at DataGenerator.Program.CreateIndividualAndSaveToDatabase() in C:\Documents and Settings\user1\Desktop\DataGeneration\DataGenerator\DataGenerator\Program.cs:line 29 at DataGenerator.Program.Main() in C:\Documents and Settings\user1\Desktop\DataGeneration\DataGenerator\DataGenerator\Program.cs:line 16 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executi开发者_运维技巧onContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: System.InvalidOperationException Message=There is an error in XML document (1, 2). Source=System.Xml StackTrace: at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader) at NHibernate.Cfg.NamedXmlDocument..ctor(String name, XmlDocument document) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\NamedXmlDocument.cs:line 27 at NHibernate.Cfg.Configuration.LoadMappingDocument(XmlReader hbmReader, String name) in d:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1774 InnerException: System.InvalidOperationException Message= was not expected. Source=2p514b3b StackTrace: at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderHbmMapping.Read109_hibernatemapping() InnerException:

**

Can somebody give me some pointers on whats going on here?

Thanks


Make sure that the mapping file's build action is set to "Embedded resource".

EDIT:

Try

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">

Note the n in nhibernate.

0

精彩评论

暂无评论...
验证码 换一张
取 消