Search code examples
sap-commerce-cloud

equals() and hashCode() override in hybris


Is there any way to override equals() and hashCode() methods for types from *-items.xml ? For example:

 <itemtype code="FaqParagraph" extends="GenericItem" autocreate="true" generate="true"
                  jaloclass="com.training.core.jalo.FaqParagraph">
            <deployment table="FaqParagraph" typecode="20004"/>
            <attributes>
                <attribute qualifier="code" type="java.lang.String">
                    <modifiers initial="true" write="false" optional="false"/>
                    <persistence type="property"/>
                </attribute>
            </attributes>
 </itemtype>

Is there any way to override the equals() and hashCode() for FaqParagraphModel ?


Solution

  • If your question is about generated **Model instances, there is no possibility to have a custom implementation for hashCode and equals. Please note that the "generated" implementation considers two instances as equals if they have the same PK and are in the same tenant.