0
我有两个实体 - Category
和Attribute
。 Category
可以有多个相关属性,并且Attribute
可以与任意数量的类别相关。协会应仅在Category
一侧提供 - Attribute
对象不知道它们与之相关的类别。如何让hibernate单向多对多关联更新?
Category.hbm.xml
<class name="Category" table="category" proxy="ICategory" entity-name="category">
<id name="id" column="id" unsaved-value="null"><generator class="identity" /></id>
...some properties...
<bag name="relatedAttributes" table="category_attribute" fetch="select">
<key column="id_category" />
<many-to-many column="id_attribute" entity-name="attribute" />
</bag>
</class>
和Attribute.hbm.xml
<class name="Attribute" table="attribute" proxy="IAttribute" entity-name="attribute">
<id name="id" column="id" unsaved-value="null" ><generator class="identity" /></id>
...some properties...
</class>
测绘工程完美搭配:
所以我这个协会为单向多到多模当前数据,直到它需要更新。我只想做的事情一样简单,因为这些:
ICategory c = (ICategory) session.get("category", 1);
c.getRelatedAttributes().add((IAttribute) session.get("attribute", 2));
session.update("category", c);
我怎样才能使这种关联更新?