【发布时间】:2020-11-11 14:36:29
【问题描述】:
我有两个对象,例如:
public class Object1 implements Serializable {
protected Integer id; // This is the PK in the xml mapping
protected Integer otherId;
}
public class Object2 implements Serializable {
protected Integer id; // This is the PK in the xml mapping
protected Set<Object1> object1List; // I want to relate this set against the "otherId" attribute
}
我有这个休眠 XML 映射:
<class name="Object1" table="Object1Table">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
<property name="otherId" type="java.lang.Integer">
<column name="other_id"></column>
</property>
</class>
<class name="Object2" table="Object2Table">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
<set name="object1List" table="Object1Table" lazy="false" fetch="join" >
<key column="other_id" /> // This is not working
<one-to-many class="Object1" />
</set>
</class>
但我不知道如何将“set”映射与“other_id”属性相关联,它仅适用于“Object1”表的 PK“id”。
有谁知道如何解决这种情况?
【问题讨论】:
-
哇。没有意识到人们仍在使用 XML 进行实体映射。我相信
column属性是指连接列的名称。one-to-many上没有property-ref属性吗?
标签: java hibernate hibernate-mapping