Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hybris - overriding existing unique attributes of an Item Type to make them non-unique

In my hybris application, I wanted to override my CustomerReview item type so that its attributes product and user are not unique anymore.

The uniqueness of these attributes are declared in the relationships between CustomerReview and Product/User. I tried adding the relationship declaration again to my extname-items.xml file and set the appropriate unique="false" attributes, as follows:

<relation generate="false" localized="false" code="ReviewToUserRel" autocreate="false">
    <sourceElement type="User" qualifier="user" cardinality="one">
        <modifiers write="false" initial="true" optional="false" unique="false" />
    </sourceElement>
    <targetElement type="CustomerReview" qualifier="customerReviews" cardinality="many">
        <modifiers write="false" initial="true" />
    </targetElement>
</relation>

This doesn't do the trick though. After I rebuild the application and Update the Running System, the user and product attributes of a CustomerReview are still unique attributes.

So what's the best solution for this problem?

like image 374
Henrique Ordine Avatar asked Mar 04 '14 07:03

Henrique Ordine


People also ask

What is the use of typecode in hybris?

typecode modifier: is used internally to create item PKs. Using typcode which already exists will cause failure. Typecode values between 0 and 10000 are reserved for hybris internal use, typecode values greater than 10000 can be used — between 0 & 32767.

What is jaloclass in hybris?

Jalo class was used in earlier version of hybris to write business logic . The problem with this is, that your code becomes tightly coupled. Its completely fine to, do not generate jalo class. Basically, when you define new type in items.xml .On build ,following classes are generated : 1. Model class 2.

What is attribute in hybris?

It means we are adding the new attribute directly in the existing item type without creating a new item type. So newly added attribute will be generated in existing Address model class. Because of which, we have to give autocreate and generate as false.


1 Answers

It's true that rewriting the relation will not override it.

Another way to solve it would be to add an attribute to the type and set that as unique. For instance emailAddress:

<itemtype code="CustomerReview" autocreate="false" generate="false">
    <attributes>
                <attribute type="java.lang.String" qualifier="email">
                    <persistence type="property" />
                    <modifiers read="true" write="true" unique="true"/>
                </attribute>
     </attributes>
</itemtype>

Then you could have multiple reviews from the same user for the same product, as long as the emailAddress differs.

like image 61
Pearl Jade Avatar answered Sep 28 '22 06:09

Pearl Jade