-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Persistent Class not found
PostPosted: Mon Nov 02, 2009 10:03 am 
Newbie

Joined: Mon Nov 02, 2009 9:52 am
Posts: 19
Hallo,

Ich arbeite mich gerade in NHibernate ein. Dazu habe ich eine simple Klasse in .NET C# geschrieben. Jedoch erhalte ich eine MappingException, sobald ich ein AddAssembly ausführe. Es deutet ja auf einen Fehler in der Mapping-file hin, denke ich. Die Eigeschaft Buildvorgang der Mappingfile steht auf Eingebettete Ressource. Vielleicht kann mir jemand helfen? Hier die Daten:

Mappingfile (Person.hbm.xml):
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
  <class name="Person, NHibernate" lazy="false">
    <id name="id" access="field">
      <generator class="native" />
    </id>
    <property name="name" access="field" column="name"/>
    <many-to-one access="field" name="parent" column="parent" cascade="all"/>
  </class>
</hibernate-mapping>


Klasse:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NHibernate
{
    class Person
    {
        public int Id { get; set; }
        public String Name { get; set; }
        public Person Parent { get; set; }
        public int OrderNumber { get; set; }
        public Person Branch { get; set; }

        public Person()
        {}

        public Person(String name, Person parent)
        {
            Name = name;
            Parent = parent;
        }

        public bool IsRoot()
        {
            return null == Parent ? true : false;
        }

        public Person GetRoot()
        {
            Person root = Parent;
            while (root.Parent != null)
            {
                root = root.Parent;
            }
            return root;
        }

        public Person Add(Person child)
        {
            child.Parent = this;
            Person ancestor = this;

            while (ancestor.Parent != null)
            {
                ancestor.Parent = ancestor.Parent.Parent;
            }

            child.Branch = ancestor;
            return child;
        }

        public void Delete()
        {
            Name = null;
            Parent = null;
        }
    }
}


Program.cs:
Code:
using System;
using System.Collections.Generic;
using System.Reflection;
using NHibernate;
using NHibernate.Cfg;

namespace NHibernate
{
    class Program
    {
        static ISessionFactory factory;

        static void Main(string[] args)
        {
            CreateFamiliy();
        }

        static void CreateFamiliy()
        {
            Person Adam = new Person("Adam", null);
            Person Peter = new Person("Peter", Adam);

            Person Jack = new Person("Jack", Peter);
            Person Charly = new Person("Charly", Adam);
            Person Tom = new Person("Tom", Charly);
            Person Mike = new Person("Mike", Tom);

            using (ISession session = OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(Adam);
                    transaction.Commit();
                }
            }
        }

        static ISession OpenSession()
        {
            ISession result = null;
            if (factory == null)
            {
                try
                {
                    Configuration c = new Configuration().Configure();
                    c.AddAssembly(typeof(Person).Assembly);
                    factory = c.BuildSessionFactory();
                    result = factory.OpenSession();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.InnerException.Message);
                    return null;
                }
            }
            return result;
        }
    }
}


Top
 Profile  
 
 Post subject: Re: Persistent Class not found
PostPosted: Tue Nov 03, 2009 6:19 am 
Newbie

Joined: Mon Nov 02, 2009 9:52 am
Posts: 19
Ich habe das Projekt noch einmal ein neues Projekt erstellt und stoße jetzt auf folgende Exception:
DuplicateMappingException: Duplicate class/entity apping NewNHibernate.Person

Ich habe aber nur eine hbm.xml und führe nur ein AddAssembly aus!?

Mapping:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="NewNHibernate.Person, NewNHibernate">

    <id name="id" column="id" type="int">
      <generator class="native" />
    </id>
    <property name="name" type="string" />
    <property name="ordernumber" type="int" />
    <property name="size" type="int" />
    <property name="root" type="string" />
    <property name="branch" type="int" />
   
  </class>
</hibernate-mapping>


Program.cs:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;

namespace NewNHibernate
{
    class Program
    {
        static void Main(string[] args)
        {
            Person Adam = new Person("Adam", null);
            Person Peter = new Person("Peter", Adam);
            Person Nathan = new Person("Nathan", Adam);
            Person Gabriel = new Person("Gabriel", Adam);
            Person Claire = new Person("Claire", Nathan);
            Person Matt = new Person("Matt", Peter);

            using (ISession session = OpenSession())
            {
                using (session.BeginTransaction())
                {
                    session.SaveOrUpdate(Adam);
                }
            }
        }

        public static ISession OpenSession()
        {
            ISession session = null;

                try
                {
                    log4net.Config.XmlConfigurator.Configure();
                    Configuration cfg = new Configuration().Configure();
                    cfg.AddAssembly(typeof(Person).Assembly);
                    session = cfg.BuildSessionFactory().OpenSession();
                }
                catch(NHibernate.MappingException ex)
                {
                    Console.WriteLine(ex.InnerException.Message);
                    return null;
                }
            return session;
        }
    }
}



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.