Emily
Emily

Reputation: 17

NHibernate issue : persistent class not known

I have two tables Person and PassportInfo with a structure as given below:

Table Person
(
PersonID uniqueidentifier not null, (PK)
Name varchar(100) not null,
Email varchar(100) not null
)

Table PassportInfo
(
ID int identity(1,1) not null Primary Key,
personID uniqueidentifier null, (FK to PersonID in Person table)
PassportNumber varchar(100) not null
)

Also this is the mapping for Person

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Project" namespace="Project">
  <class name="classperson" table="Person" >
    <id name="ID" type="System.Guid" column="personID">
      <generator class="Guid"/>
    </id>
    <property name="Name" column="Name" type="System.String" length="100" not-null="true" />
    <property name="Email" column="Email" type="System.String" length="100" not-null="true" />
    <one-to-one name="classpassportinfo" class="classpassportinfo" constrained="true" />
  </class>
</hibernate-mapping>

This is the mapping for PassportInfo

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Project" namespace="Project">
  <class name="classpassportinfo" table="PassportInfo" >
    <id name="ID" type="System.Int32" column="ID">
      <generator class="identity"/>
    </id>
    <property name="PassportNumber" column="PassportNumber" type="System.String" length="100" not-null="true" />
    <one-to-one name="classperson" class="classperson"  />
  </class>
</hibernate-mapping>

This is the Object Class for Person

namespace Project
{
    [Serializable]
    public class classperson : Base<System.Guid>
    {
        private System.String _Name;
        private System.String _Email;
        private classpassportinfo _classpassportinfo;

         public classperson()
        {
        }

        public classperson(System.Guid id)
        {
            base.ID = id;
        }

         public virtual System.String Name {
             get { return _Name; }
             set { _Name = value;}
         }

         public virtual System.String Email {
             get { return _Email; }
             set { _Email = value;}
         }

         public virtual classpassportinfo classpassportinfo {
             get { return _classpassportinfo; }
             set { _classpassportinfo = value;}
         }
    }
}

Finally this is the object class for PassportInfo

namespace Project
{
    [Serializable]
    public class classpassportinfo :Base<Systme.Int32>
    {
        private System.String _PassportNumber;
        private classpassportinfo _classpassportinfo;

         public classpassportinfo()
        {
        }

        public classpassportinfo(System.Int32 id)
        {
            base.ID = id;
        }

         public virtual System.String PassportNumber {
             get { return _PassportNumber; }
             set { _PassportNumber = value;}
         }

         public virtual classperson classperson {
             get { return _classperson; }
             set { _classperson = value;}
         }
    }
}

When I execute above code, i am getting and error saying persistent class not known: Project.classpassportinfo. I am new to nhibernate. Any help in this appreciated.

Upvotes: 0

Views: 1671

Answers (1)

Joe P
Joe P

Reputation: 45

To elaborate and clarify @Fran's comment for anyone else struggling with this problem...

For me, in Visual Studio this issue was resolved by:

  1. Open the solution explorer (Project structure navigator)
  2. Locate the mapping file passportinfo.hbm.xml
  3. Right click and choose properties
  4. Under the advanced tab, make sure "Build Action" is set to "Embedded Resource"

The issue should be resolved now. Good luck

Upvotes: 2

Related Questions