0

我得到了例外

初始 SessionFactory 创建 failed.org.hibernate.MappingException:来自表 CountryList 的关联引用了未映射的类:com.abegaa.model.StateListPojo

对于这两个 hbm 文件之间的休眠映射

第一个 CountryList 和 StateList

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.abegaa.model">

 <class name="CountryListPojo" table="CountryList">
 <id name="Id" column="Id">
 <generator class="increment"></generator>
  </id>

 <many-to-one name="Db_CountryId" column="Db_CountryId" class="StateListPojo"></many-to-one>

  <property name="Db_CountryName" column="Db_CountryName"></property>
  </class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.abegaa.model">
  <class name="StateListPojo" table="StateList">

 <id name="Id" column="Id">
 <generator class="increment"></generator></id>

 <set name="Db_CountryId">
    <key column="Db_CountryId"></key>
<one-to-many class="CountryListPojo"/>
  </set>

  <property name="Db_StateId" column="Db_StateId"/>
  <property name="Db_StateName" column="Db_StateName"/>
  </class>
</hibernate-mapping>

这是我的课。

public class CountryListPojo
{

       private long Id;
private String Db_CountryId;
private String Db_CountryName;
    //get and set
} 

 public class StateListPojo 
{

private String Id;
private String Db_CountryId;
private String Db_StateId,Db_StateName;
 //get and set
 }

我不明白我在哪里做错了?

4

1 回答 1

0

试试这个

public class CountryListPojo
{

   private long Id;
   private String Db_CountryId;
   private String Db_CountryName;
   private Set<StateListPojo > stateListPojos = new HashSet<StateListPojo ();
//get and set
}

public class StateListPojo 
{

    private String Id;
    CountryListPojo Db_CountryId = new CountryListPojo();
    private String Db_StateId,Db_StateName;
    //get and set
 }

和 hbm 应该有

 <?xml version="1.0"?>
 <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
       "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

 <hibernate-mapping package="com.abegaa.model">

  <class name="CountryListPojo" table="CountryList">
      <id name="Id" column="Id">
        <generator class="increment"></generator>
      </id>
    <property name="Db_CountryName" column="Db_CountryName"></property>
    <set name="stateListPojos">
         <key><column name="Db_CountryId" /></key>
         <one-to-many class="StateListPojo" />
     </set>
  </class>
</hibernate-mapping>

<?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
        <hibernate-mapping package="com.abegaa.model">
            <class name="StateListPojo" table="StateList">

              <id name="Id" column="Id">
                  <generator class="increment"></generator>
              </id>
              <many-to-one class="CountryListPojo" name="Db_CountryId">
                  <column name="Db_CountryId"></column>
               </many-to-one>
              <property name="Db_StateId" column="Db_StateId"/>
              <property name="Db_StateName" column="Db_StateName"/>
           </class>
       </hibernate-mapping>
于 2012-08-14T06:08:38.620 回答