简体   繁体   中英

error “The element 'class' in has invalid child element 'set' in namespace ” when mapping hbm file

H want to use inheritance in my application but when I run, my hbm mapping file has error. my code is here

 public class StudentDao
    {

        public virtual int Id { get; set; }
        public virtual string FirstName { get; set; }
        public virtual string LastName { get; set; }
        public virtual StudentDegreeType Degree { get; set; }
        public virtual string Field { get; set; }
        public virtual IEnumerable<StudentCourse> StudentCourses { get; set; }

my mapping file is :

    <?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="Tosan.Sevrice.DataAccess" namespace="Tosan.Sevrice.DataAccess.Dao" xmlns="urn:nhibernate-mapping-2.2">
  <class name="StudentDao" table="STUDENTT" lazy="true" >
    <id name="Id" column="ID" >
      <generator class="increment"> </generator>
    </id>
    <discriminator column="Degree"/>

    <property name="FirstName" column="FIRSTNAME" />
    <property name="LastName" column="LASTNAME" />
    <!--<property name="Degree" column="DEGREE" />-->
    <property name="Field" column="FIELD" />

    <subclass name="MasterStudent" discriminator-value="1">
         <property name="َArticle"  />
    </subclass>
    <subclass name="BachelorStudent" discriminator-value="2">

    </subclass>

    <set name="StudentCourses" table="StudentCourse" inverse="true" cascade="all,delete-orphan">
      <key column="ID"/>
      <one-to-many class="StudentCourse"/>
    </set>

  </class>
</hibernate-mapping>

I use a relationship tag in my file mapping 'set'

my child classes is :

public class BachelorStudent : StudentDao
    {
    }
}

and the next child class :

public class MasterStudent : StudentDao
    {
        public virtual bool Article { get; set; }
    }
}

after I run this the error bellow come out :

"The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'set' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'subclass, loader, sql-insert, sql-update, sql-delete, filter, resultset, query, sql-query' in namespace 'urn:nhibernate-mapping-2.2'."

what should I do??

set elements needs to be defined before subclass elements. ie:

<set name="StudentCourses" table="StudentCourse" inverse="true" cascade="all,delete-orphan">
  <key column="ID"/>
  <one-to-many class="StudentCourse"/>
</set>

<subclass name="MasterStudent" discriminator-value="1">
     <property name="َArticle"  />
</subclass>
<subclass name="BachelorStudent" discriminator-value="2">

</subclass>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM