如何在Hybris中定义级联删除items.xml?

How to define cascade delete in the Hybris items.xml?

我想在删除父对象时自动删除子对象。

例如,我有类型 Car 和 Engine。这辆车有一个属性引擎。删除 Car 对象时,应自动删除绑定到此 Car 的 Engine 对象。

提前致谢各位

使用 "partOf" 修饰符:

<itemtype code="Car" ...>
  ...
  <attributes>
    ...
    <attribute qualifier="engine" type="Engine">
      <persistence type="property" />
      <modifiers partof="true" />
    </attribute>
  </attributes>
</itemtype>

也可以与关系一起使用:

<relation code="CarToEngineRelation"...>
  <sourceElement type="Car" ...>
  </sourceElement>
  <targetElement type="Engine" ...>
      <modifiers partof="true"/>
  </targetElement>
</relation>

@Johannes 很好地树立了榜样。

让我详细说明一下

什么是 PartOf?

PartOf修饰符用于定义Parent对象和Child对象之间的聚合关系。为了更好地解释它,我会说 PartOf 用于定义级联删除。当我们删除父对象时,它的所有子对象(partOf)将被自动删除。

您可以在修饰符标签的帮助下在属性或关系中定义它。喜欢

<itemtype code="User"
          extends="Principal"
          jaloclass="de.hybris.platform.jalo.user.User"
          autocreate="true"
          generate="true">
    <deployment table="Users" typecode="4" propertytable="UserProps"/>
    <attributes>
        ...
        ...
        <attribute autocreate="true" qualifier="addresses" type="AddressCollection">
            <modifiers partof="true"/>
        </attribute>
        <attribute autocreate="true" qualifier="carts" type="CartCollection">
            <modifiers partof="true"/>
        </attribute>
    </attributes>
</itemtype>

如果我们删除用户,其所有地址和购物车都将被删除。


找到详细的post here