Skip to Content
Technical Articles
Author's profile photo Sagar Bhambhani

Chapter 3| Commerce cloud Data modelling

Hi There,

Welcome to the 3 blog post of SAP Commerce cloud.
As we have already discussed the basic building blocks of hybris, I would like to discuss DATA MODELLING in hybris today.

So, there are 2 things that you need to know :

1) Items.xml – Where you define the new item types or extend the existing item types

2) Items.xsditems.xml file is validated against this XSD file. A type definition order that doesn’t conform to the items.xsd causes SAP Commerce to fail the extension build.

So, According to items.xsd,
there has to be a fixed structure that we need to follow while defining item types.:


<items xmlns:xsi=”” xsi:noNamespaceSchemaLocation=”items.xsd“>

<atomictypes> </atomictypes>
<collectiontypes> </collectiontypes>
<enumtypes> </enumtypes>
<maptypes> </maptypes>
<relations> </relations>
<itemtypes> </itemtypes>

Let us go one by one:

Atomic Types: 

AtomicTypes are the most basic types available in the hybris.
They are the illustration of Java number and String item types, which include java.lang.Integer or java.lang.String.
We usually don’t need to define new ones.


<atomictype class=“java.lang.String” extends=“java.lang.Object” autocreate=“true” generate=“false”/>


collection types:

Collection basically contains elements of the same type.
For example: A collection of String will contain the elements of String element type


<collectiontype code="AddressCollection" elementtype="Address" autocreate="true" generate="false"/>

<collectiontype code=”StringCollection” elementtype=”java.lang.String” autocreate=”true” generate=”false”/>

Enum Types:

This is used when we need Attributes with pre-defined values.

For Example, we need titles like Dr., Mr., Ms.


<enumtype code=”enumSampleType” autocreate=”true” generate=”true” dynamic = “true”>
<value code=”sample1″/>
<value code=”sample2″/>
<value code=”sample3″/>

You can set the dynamic=”true” to allow adding values at runtime(by default, dynamic=” false”).


Map Types:

 Map Type is a collection of key-value pairs.

For each key (referred to as argument), there is a corresponding value (referred to as return type).


<maptype code=“addressMap”  argumenttype=“java.lang.String”  returntype=“Address”                 autocreate=“true”  generate=“false”/>
A very common use of MapTypes is localized values – values that may differ in every language available in the system, like product descriptions in German and English.
Relation types:

Relation types help us to maintain the m:n relation between 2 tables.

If you delete an item from a relation, neither the item you seem to delete nor its related item is deleted, only the LinkItem is removed. In other words, both the source item and the target item remain, only the link between them is removed.

there are 2 types of relations hybris supports one to many & many to many.

Extra table will be created only for many to many relations.


<relation code=”CategoryProductRelation” autocreate=”true” generate=”true” localized=”false”>
<deployment table=”Cat2ProdRel” typecode=”143″/>

<sourceElement qualifier=”supercategories” type=”Category” cardinality=”many” ordered=”false”>
<description>Super Categories</description>
<modifiers read=”true” write=”true” search=”true” optional=”true”/>

<targetElement qualifier=”products” type=”Product” cardinality=”many” collectiontype=”list” ordered=”true”>
<modifiers read=”true” write=”true” search=”true” optional=”true”/>

Relations are preferred over Collections in case of need for back traceability.

Item Types


This is the main block where we define the table and its attribute details.

There are 3 ways to configure:

1) Define the new item type without extending any existing item type

<itemtype code=“New” autocreate=“true” generate=“true”>
<deployment table=“New” typecode=“11000” />

2) Define the new item type by extending it with the existing item type

<itemtype code=“NewAddress” extends=“Address” autocreate=“true” generate=“true”

3) Define the existing item type again with new attributes

      <itemtype code=“Address” autocreate=“false” generate=“false”
AUTOCREATE– create a new database entry for this type at the initialization/update process. (set it to true for the first definition of item type)
GENERATE– to generate a new jalo class for this type during build time
DEPLOYMENT TABLE- specifies the table name.
TYPECODE– a unique number that ranges between  10000 and 32767.
After defining the item types we need to add attributes inside the <attributes> tag.
<attribute qualifier=“password” type=“java.lang.String” >
                        <modifiers unique=“false” encrypted=“true”/>
                       <persistence type=“dynamic” attributeHandler=“customerSiteAge”/>
There are various modifiers, some of which are mentioned below:
Read– attribute is readable
Write–  attribute is writable
Search– attribute is searchable by flexibleSearch
Optional– attribute is mandatory to fill while saving the model (By default true).
Unique – to make sure field values are unique always
Encrypted – to encrypt data before saving it to the database
Persistence type – To store data inside the database or just retrieve a value based on some logic. ( we define attrbiuteHandler which basically is a class that extends AbstractDynamicAttributeHandler)
Redeclare– If you want to redeclare or change any modifiers of an attribute.
For more information, you can read on

and if any queries please feel free to drop comment below.

Thanks for the Read.

Signing off!

Sagar Bhambhani.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.