on ‎2018 Feb 20 3:29 PM
Hi All,
Could you please help me in creation of Composite Primary key in for the Customer Item type.
Many Thanks in advance.
Regards, .M
Request clarification before answering.
Hi Praveen,
You can write items.xml like below,
<itemtype code="Customer" generate="true" autocreate="true">
<deployment table="Customer" typecode="14010" />
<attributes>
<attribute type="java.lang.String" qualifier="id">
<modifiers optional="false" unique="true"/>
<persistence type="property" />
</attribute>
<attribute type="java.lang.String" qualifier="ssn">
<modifiers optional="false" unique="true"/>
<persistence type="property" />
</attribute>
</attributes>
</itemtype>
<itemtype code="Customer" generate="true" autocreate="true">
<deployment table="Customer" typecode="14010" />
<attributes>
<attribute type="java.lang.String" qualifier="id">
<modifiers optional="false"/>
<persistence type="property" />
</attribute>
<attribute type="java.lang.String" qualifier="ssn">
<modifiers optional="false"/>
<persistence type="property" />
</attribute>
</attributes>
<indexes>
<index name="CustomerUnqIdx" unique="true">
<key attribute="id" />
<key attribute="ssn" />
</index>
</indexes>
</itemtype>
I prefer approach one rather than second approach. Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Parveen,
I guess you're looking for here mentioned code. Please do let me know if you have any concerns. Thanks
<itemtype code="Customer"
extends="User"
jaloclass="de.hybris.platform.jalo.user.Customer"
autocreate="false"
generate="false">
<attributes>
<attribute autocreate="true" qualifier="socialSecurityNumber" type="java.lang.String">
<modifiers unique="true"/>
<persistence type="property"/>
</attribute>
</attributes>
</itemtype>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Praveen - it would help to understand what you are trying to achieve.
Note - OOTB hybris creates native unique primary keys - by way of the item PK. Which is used to identify the record as a unique record.
Adding unique=true to the attribute via the items.xml file (or to many attributes) further selects attributes of the type that will further uniquely identify a record and prevent duplicates of the record - based on the collection of those 'unique' attributes.
This can also be achieved by adding an index for a number of attributes - creating a unique index.
Let me know what you are trying to achieve and i'll try to be more specific with the answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ,
Thanks for your answer. I am implementing Customer registration and in which I have already customerId as unique and I want one more field needs to be unique like Social Security Number.
Here for Customer I have to declare two fields as Unique i.e. customerID and Social Security Number. Here my question how can I declare second attribute as Unique in items.xml ?
Regards, .M
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.