What is the PartOf modifier in Hybris items.xml?
What is PartOf?
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?
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>
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>
If we remove a user, its all addresses & carts will be removed.
Thanks for the explanation :)
ReplyDeleteThank youuuuu
ReplyDeleteThis is really useful article. Thanks!
ReplyDeleteGood explanation Ankit keep it up
ReplyDeleteHello ,
ReplyDeleteHow i can change content GeneratedAbstractOrderEntry in hybris please if you have any ideas ?
Good explanation.
ReplyDeleteHi Ankit,
ReplyDeleteI do have a question, in your first example i.e. OOTB code, if I want to make the partOf modifier as false then how we can achieve it.
"entryNumber"