Hibernate中的<element> vs <composite-element> </composite-element> </element>

时间:2014-12-30 10:26:33

标签: hibernate hibernate-mapping

<element><composite-element>之间有什么区别?我在标记中看到了<composite-element><element>个标记。这些元素是用于收藏吗?在什么情况下这些元素都适用?

1 个答案:

答案 0 :(得分:2)

当您想要映射&#34;简单&#34;的集合时,使用

<element>。值。请参阅6.2.4. Collections of values and many-to-many associations

中的此示例
<set name="names" table="person_names">
    <key column="person_id"/>
    <element column="person_name" type="string"/>
</set>

<composite-element>用于映射components的集合,即由简单类型组成的哑类。这个例子来自8.2. Collections of dependent objects

<set name="someNames" table="some_names" lazy="true">
    <key column="id"/>
    <composite-element class="eg.Name"> <!-- class attribute required -->
        <property name="initial"/>
        <property name="first"/>
        <property name="last"/>
    </composite-element>
</set>