-->
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.  [ 10 posts ] 
Author Message
 Post subject: Help debugging MappingException: Could not find class error
PostPosted: Tue Sep 19, 2006 3:41 pm 
Newbie

Joined: Sat Nov 19, 2005 1:01 pm
Posts: 9
Hi.

It's been a while since I did an NHibernate project and I'm positive that this error i'm getting is the result of something boneheaded on my part but I just don't see it.

I'm just doing a simple test app to get back familiar with the NHibernate way of doing things and my first relationship definition is failing. I've got Users, Permissions and a join table called UserPermissions (UserPermID, UserID, PermID.)

When I run the code I get the exception listed below. Can anybody see the nature of my undoubtedly lame mistake?

I'd search for the error on here but I'm getting an error message from the search function. Checked the FAQ but to no avail.

Thanks.

NHibernate version:
1.2.0Alpha1

Mapping documents:
User:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
    <class name="MySqlTest.User, MySqlTest" table="users">
        <id name="UserID" column="UserID" type="Int32" length="20">
            <generator class="identity" />
        </id>
        <property name="Name" column="name" type="String" length="40"/>
        <property name="Password" type="String" length="20"/>
        <set name="Permissions" table="UserPermissions" inverse="false" lazy="true">
            <key column="UserID"/>
            <many-to-many class="MySqlTest.Permission" column="permID"/>
        </set>
    </class>
</hibernate-mapping>


Permission:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
    <class name="MySqlTest.Permission, MySqlTest" table="permissions">
        <id name="PermID" type="Int32">
            <generator class="identity" />
        </id>
        <property name="Name" column="name" type="String" length="40"/>
    </class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Code:
         Configuration cfg = new Configuration();
         cfg.AddAssembly("MySqlTest");

         ISessionFactory factory = cfg.BuildSessionFactory(); //breaks here
         ISession session = factory.OpenSession();
         Permission addPerm = (Permission)session.Load(typeof(Permission), 1);
         Permission editPerm = (Permission)session.Load(typeof(Permission), 2);

         User u = (User)session.Load(typeof(User), 1);
         u.Permissions.Add(addPerm);

         session.Save(u);
         
         session.Close();


Full stack trace of any exception that occurs:
Code:
"NHibernate.MappingException: could not find class: MySqlTest.Permission ---> System.TypeLoadException: Could not load type 'MySqlTest.Permission', check that type and assembly names are correct\r\n   at NHibernate.Util.ReflectHelper.ClassForName(String name) in c:\\net\\nhibernate\\nhibernate\\src\\NHibernate\\Util\\ReflectHelper.cs:line 160\r\n   at NHibernate.Cfg.HbmBinder.ClassForFullNameChecked(String fullName, String errorMessage) in c:\\net\\nhibernate\\nhibernate\\src\\NHibernate\\Cfg\\HbmBinder.cs:line 82\r\n   --- End of inner exception stack trace ---\r\n   at NHibernate.Cfg.HbmBinder.ClassForFullNameChecked(String fullName, String errorMessage) in c:\\net\\nhibernate\\nhibernate\\src\\NHibernate\\Cfg\\HbmBinder.cs:line 86\r\n   at NHibernate.Cfg.HbmBinder.ClassForNameChecked(String name, Mappings mappings, String errorMessage) in c:\\net\\nhibernate\\nhibernate\\src\\NHibernate\\Cfg\\HbmBinder.cs:line 100\r\n   at NHibernate.Cfg.HbmBinder.BindManyToOne(XmlNode node, ManyToOne model, String defaultColumnName, Boolean isNullable, Mappings mappings) in c:\\net\\nhibernate\\nhibernate\\src\\NHibernate\\Cfg\\HbmBinder.cs:line 826\r\n   at NHibernate.Cfg.HbmBinder.BindCollectionSecondPass(XmlNode node, Collection model, IDictionary persistentClasses, Mappings mappings) in c:\\net\\nhibernate\\nhibernate\\src\\NHibernate\\Cfg\\HbmBinder.cs:line 1545\r\n   at NHibernate.Cfg.HbmBinder.BindSetSecondPass(XmlNode node, Set model, IDictionary persistentClasses, Mappings mappings) in c:\\net\\nhibernate\\nhibernate\\src\\NHibernate\\Cfg\\HbmBinder.cs:line 2046\r\n   at NHibernate.Cfg.SetSecondPass.SecondPass(IDictionary persistentClasses) in c:\\net\\nhibernate\\nhibernate\\src\\NHibernate\\Cfg\\HbmBinder.cs:line 1788\r\n   at NHibernate.Cfg.AbstractSecondPass.DoSecondPass(IDictionary persistentClasses) in c:\\net\\nhibernate\\nhibernate\\src\\NHibernate\\Cfg\\HbmBinder.cs:line 1713\r\n   at NHibernate.Cfg.Configuration.SecondPassCompile() in c:\\net\\nhibernate\\nhibernate\\src\\NHibernate\\Cfg\\Configuration.cs:line 885\r\n   at NHibernate.Cfg.Configuration.BuildSessionFactory() in c:\\net\\nhibernate\\nhibernate\\src\\NHibernate\\Cfg\\Configuration.cs:line 997\r\n   at MySqlTest.Form1.Form1_Load(Object sender, EventArgs e) in c:\\documents and settings\\skain\\my documents\\visual studio projects\\mysqltest\\form1.cs:line 120"


Name and version of the database you are using:
MySql 5.0

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 3:58 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
yeah, it looks fine to me too from here. are the .hbm.xml files marked as Embedded Resource? i know that's a boneheaded comment, but just eliminating the obvious....

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 3:59 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
and also, are you using VisualStudio or VisialWebDeveloper (the lightweight version of VisualStudio)?

-d


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 4:02 pm 
Newbie

Joined: Sat Nov 19, 2005 1:01 pm
Posts: 9
Don't worry about suggesting the obvious. I'm fairly certain that the answer will be an obvious one once someone points it out!

They are both embedded resources. I'm using VS2K3.

If I comment out the relationship definitinon in the .hbm file I can use both objects just fine. That's what's really confusing me.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 4:17 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
okay, the vs question relates to a problem with referencing classes specifically since VisualWebDeveloper does some sort of dynamic compile and assembly naming (i don't use it, i've just seen references to it on the board).

post your class files?

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 4:24 pm 
Newbie

Joined: Sat Nov 19, 2005 1:01 pm
Posts: 9
Here you go:

Code:
using System;

namespace MySqlTest
{
   /// <summary>
   /// Summary description for Permission.
   /// </summary>
   public class Permission
   {
      private int permID;
      private string name;


      public virtual int PermID
      {
         get
         {
            return permID;
         }
         set
         {
            permID = value;
         }
      }

      public virtual string Name
      {
         get
         {
            return name;
         }
         set
         {
            name = value;
         }
      }


      public Permission()
      {
         //
         // TODO: Add constructor logic here
         //
      }
   }
}



Code:
using System;
using Iesi.Collections;

namespace MySqlTest
{
   /// <summary>
   /// Summary description for User.
   /// </summary>
   public class User
   {
      private int userID;
      private string name;
      private string password;
      private ISet permissions = new HashedSet();


      public virtual ISet Permissions
      {
         get
         {
            return permissions;
         }
         set
         {
            permissions = value;
         }
      }




      public virtual int UserID
      {
         get
         {
            return userID;
         }
         set
         {
            userID = value;
         }
      }

      public virtual string Name
      {
         get
         {
            return name;
         }
         set
         {
            name = value;
         }
      }

      public virtual string Password
      {
         get
         {
            return password;
         }
         set
         {
            password = value;
         }
      }



      public User()
      {
         //
         // TODO: Add constructor logic here
         //
      }
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 4:38 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
damn, i found it:

Code:
<many-to-many class="MySqlTest.Permission" column="permID"/>

needs to be:
Code:
<many-to-many class="MySqlTest.Permission, MySqlTest" column="permID"/>

sheesh. can't believe i missed that one. sorry for the wild goose chase.

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 4:48 pm 
Newbie

Joined: Sat Nov 19, 2005 1:01 pm
Posts: 9
Thanks. That was it. I can't believe I missed it either.

But now I get a lazy initialization exception at the line where I try to add the new permission. How do I fix that? (Or should I start another topic? I really wish the search was working . . .)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 4:58 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
that lazy init is happening because you have lazy="true" and your session is closed. try the search again. i was just using it for a different problem i am having. the easiest method is to set lazy=false but then you don't get the benefit of figuring out how sessions work ;)

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 5:07 pm 
Newbie

Joined: Sat Nov 19, 2005 1:01 pm
Posts: 9
Actually it was because I had the name of the join table wrong in the mapping file. How embarrassing! Anyways it looks like I'm rolling now.

Thanks for all the help!


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