-->
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.  [ 4 posts ] 
Author Message
 Post subject: [noob]NHibernate.MappingException: could not find class
PostPosted: Tue Dec 27, 2005 11:06 am 
Beginner
Beginner

Joined: Fri Dec 23, 2005 6:05 am
Posts: 42
Hello,
I was just testing a NHibernate one-to-one relation, when I ran into this error.

Code:
Unbehandelte Ausnahme: NHibernate.MappingException: Error reading resource: WindowsApplication1.Person.hbm.xml ---> NHibernate.MappingException: could not find class: WindowsApplication1.Item ---> System.TypeLoadException: Der Typ WindowsApplication1.Item in der Assembly NHibernate, Version=1.0.1.0, Culture=neutral, PublicKeyToken=154fdcb44c4484fc konnte nicht geladen werden.
   at System.Type.GetType(String typeName, Boolean throwOnError)
   at NHibernate.Util.ReflectHelper.ClassForName(String name)
   at NHibernate.Cfg.Binder.ClassForFullNameChecked(String fullName, String errorMessage)
   --- Ende der internen Ausnahmestapelüberwachung ---
   at NHibernate.Cfg.Binder.ClassForFullNameChecked(String fullName, String errorMessage)
...


The only thing i wanted is to use an Classe named Item in my Class Person. I decided to use a one-to-one relation. and here is how i did it.
For the Person:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="WindowsApplication1.Person, WindowsApplication1" table="persons">
      <id name="Id" column="userid" type="Int32">
         <generator class="native" />
      </id>
      <property name="Firstname" column="firstname" type="String(50)" />
      <property name="Lastname" column="lastname" type="String(50)" />
        <one-to-one name="MyItem" class="WindowsApplication1.Item" constrained ="true" />
   </class>
</hibernate-mapping>
Code:
using System;
namespace WindowsApplication1
{
   public class Person
   {
      private Item _myItem;
      private int _id = 0;
      private string _firstname;
      private string _lastname;

      public Person() {}
      
      public int Id{...}
      public Item MyItem{...}
      public string Firstname{...}
      public string Lastname{...}

   }
}


And for the Item:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="WindowsApplication1.Item, WindowsApplication1" table="item">
      <id name="Id" column="itemid" unsaved-value ="0" type="Int32">
      <generator class="native" />
      </id>
      <property name="Name" column="name" type="String(50)" />      
   </class>
</hibernate-mapping>
Code:
using System;
namespace WindowsApplication1
{
   public class Item
   {
      private string _name;
      private int _id;
      public Item(){}
      public int Id{...}
      public string Name{...}
   }
}


It breaks with the error message at this line:
Code:
...
   config.AddClass(typeof(WindowsApplication1.Item));
   config.AddClass(typeof(WindowsApplication1.Person)); // <-- this one fails
...


But why doesn't it find the class?

Thanks, and best regards.

El Gringo


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 27, 2005 1:22 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This was discussed here just a few posts back. You forgot to add the assembly name to class attribute of <one-to-one>.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 28, 2005 1:53 am 
Beginner
Beginner

Joined: Fri Dec 23, 2005 6:05 am
Posts: 42
sergey wrote:
This was discussed here just a few posts back. You forgot to add the assembly name to class attribute of <one-to-one>.


Ups, sorry. You are right. But it is hard to search for a problem, if you don't know what problem it is. :)
By the way, I solved it also by leaving out the class attribute.

Code:
...
<one-to-one name="MyItem" cascade="all" constrained="true"/>
...


So why should i use a class attribute at all? Or will NHibernate determine the correct class only if it is in the same assembly?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 28, 2005 7:13 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You don't need to use class at all.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.