cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Composite Primary Key

Former Member
0 Likes
2,792

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

Accepted Solutions (0)

Answers (3)

Answers (3)

bhavirisetty
Active Participant
0 Likes

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

0 Likes

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>

 

Former Member
0 Likes

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.

Former Member
0 Likes

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