Definition
PartOf modifier is used to define the aggregation relationship between Parent and Child objects. To explain it better I would say PartOf is used to defining cascade delete. When we delete a Parent object then all its child objects(partOf) will be deleted automatically.
PartOf modifier is used to define the aggregation relationship between Parent and Child objects. To explain it better I would say PartOf is used to defining cascade delete. When we delete a Parent object then all its child objects(partOf) will be deleted automatically.
Why or When to use PartOf?
PartOf may make sense when the relationship involves "is part of" description. For example, an OrderEntry record(AbstractOrderEntry) is part of its parent Order(AbstractOrder), and older entries will never be shared between multiple orders. If the Order were to vanish, the OrderEntry should as well, and an order entry without an Order would be a problem.
How to use PartOf?
Looking into the following items.xml snippet we can able to understand the importance of PartOf
This also can be defined at the attribute level. Like
<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 read="true" write="true" search="false" optional="true" partof="true"/>
<persistence type="jalo"/>
</attribute>
<attribute autocreate="true" qualifier="carts" type="CartCollection">
<modifiers read="true" write="true" search="false" optional="true" partof="true"/>
<persistence type="jalo"/>
</attribute>
</attributes>
</itemtype>
On the removal of an order, if we want to remove all associated order entries automatically, then we can define partOf in its relation like
<relation code="AbstractOrder2AbstractOrderEntry" localized="false" generate="true" autocreate="true">
<sourceElement type="AbstractOrder" qualifier="order" cardinality="one">
<modifiers read="true" write="true" search="true" optional="true"/>
<custom-properties>
<property name="ordering.attribute">
<value>"entryNumber"</value>
</property>
</custom-properties>
</sourceElement>
<targetElement type="AbstractOrderEntry" qualifier="entries" cardinality="many" collectiontype="list"
ordered="false">
<modifiers read="true" write="true" search="true" optional="true" partof="true"/>
</targetElement>
</relation>
Comments
Post a Comment