我收到了异常
初始SessionFactory创建失败..org.hibernate.MappingException:表CountryList中的关联引用未映射的类:com.abegaa.model.StateListPojo
用于hibernate这两个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
}
我无法理解我在哪里做错了?
答案 0 :(得分: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>