开发者

Hibernate - set of compound values

I need a Collection of compound values in Hibernate. Something like:

class Parent {
    Set<Child> children;
}

class Child {
    String property;
    String anotherProperty;
    MyOtherClass oneToOneClass;
}

The key requirement is that elements in this collection are value objects. When I saveOrUpdate the Parent it also saves its children.

More importantly when I create another Parent with children based on the same set, these children need to be persisted separately. That's why regular one-to-many does not work for me.

Is there a clean way I can do it with Hibernate? Something like collection of values described here: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/collections.html - but for a concrete, compound class.

I prefer solutio开发者_如何学Cn in XML rather than annotations.


Normally you map this as composite-element

<set ... >
  <key .../>
  <composite-element class="Child" ...>
    <property name="property"/>
    <property name="anotherProperty"/>
    <nested-composite-element name="oneToOneClass">
      <property name="..."/>
    </nested-composite-element>
</set>

See Component Mapping.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜