0
我有一个表示一个表的域对象类。这个类与另一个表有关联,但是源类的属性与目标类的属性没有相同的名称,我不知道如何休眠映射它。如何在Hibernate中映射一组对象而不用主键同名?
下面是类的一个例子为具有集(一个CT许多ř实例):
public class CT {
// This is the property in the property-ref down below
private String b;
// The set of Rs I want to get - there may be none that correspond to a CT instance.
private Set rs;
}
public class R {
// This property is mapped to the column name below.
private String rBc;
}
<!--Snippet of the mapping for class CT-->
<set name="rs" lazy="true" sort="MyComparator" table="R" >
<key column="R_COLUMN_NAME_THAT_REPRESENTS_THE_RELATIONSHIP" property-ref="b" />
<one-to-many class="CLASS_THAT_R_IS" />
</set>
休眠接受此映射,但是当我拉起集合Rs的从CT实例我知道应该存在,我只是得到一个空的PersistentSet。
请注意,每个CT实例可能没有或多于一个R是完全可能的。这就是为什么我有比较器在那里 - 我无法弄清楚如何轻松地告诉Hibernate如何执行没有显式SQL的ORDER BY子句(我在Hibernate映射中犹豫不决)。
难道某人帮助我在这里?
我没有清楚地知道对象的一面,你能说更多关于对象在对象一边做什么吗? CT和R的生命周期和所有权状况? 我已经成功地将我的所有藏品编写成多对一。在多对一和一对多之间你可以做什么似乎有区别。 – PanCrit 2009-06-19 17:11:42