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



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

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

提前感谢,伙计们

使用 "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 用于定义级联删除。当我们删除父对象时,它的所有子对象(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>

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


在此处查找详细帖子

最新更新