我有 2 个类:用户和家庭,但在运行时不能“加入”它们(如果我删除属性没有问题),我得到:
SEVERE: IllegalArgumentException in class: User, setter method of property: family
Apr 07, 2013 11:16:41 AM org.hibernate.property.BasicPropertyAccessor$BasicSetter set
SEVERE: expected type: org.hibernate.mapping.Set, actual value: org.hibernate.collection.PersistentSet
班级:
public class User
{
//....//
private Set family;
//...//
public void setFamily(Set fam)
{
this.family = fam;
}
public Set getFamily()
{
return this.family;
}
}
public class Factory
{
//...//
tx = session.beginTransaction();
List users = session.createQuery("FROM User").list(); //is it a query issue ?
allUsers = new User[users.size()];
for (Iterator iterator = users.iterator(); iterator.hasNext();)
{
User user = (User) iterator.next();
allUsers[i] = user;
System.out.print("\nFirst Name: " + user.getName());
i++;
}
tx.commit();
//....//
}
配置:
<hibernate-mapping>
<class name="User" table="users">
<meta attribute="class-description"> This class contains the employee detail. </meta>
<id name="id" type="int" column="user_id"> <generator class="native"/> </id>
<set name="family" cascade="all">
<key column="family_id"/>
<one-to-many class="Family"/>
</set>
<property name="name" column="user_name" type="string"/>
<property name="surname" column="user_surname" type="string"/>
<property name="income" column="user_income" type="int"/>
<property name="costs" column="user_costs" type="int"/>
</class>
<class name="Family" table="families">
<meta attribute="class-description"> This class contains the certificate records. </meta>
<id name="id" type="int" column="family_id"><generator class="native"/></id>
<property name="name" column="family_name" type="string"/>
</class>
</hibernate-mapping>
我是休眠新手,无法解决这个问题...我尝试更改配置文件,更改查询但仍然没有运气 PS:我在用户和家庭表中只有 1 个条目;