Items.xml

The data model of hybris is defined declaratively in items.xml. This file is like the nervous system of Hybris project. Every data definition starts from here. This file can be used to define any data structure used in project.

Below are few important points about items.xml

  • The item type in itself, is of type Item.
  • The instance of item type are stored is item type table, but the item type defination is stored in composedType. For example,for the Student item type, the instances of Student will be stored in Student table, but the definition of Student will be stored in composedType table.
  • Any extension can have a items.xml file to define data model used in extension. But this file is not mandatory to have.
  • The order in which the types are declared is very important. The order in which types are defined must conform to below
  • Atomic types
  • collection types
  • enum types
  • map types
  • relation types
  • item types
  • GenericItem is the default parent of each item type.
  • We can extend one item type using keyword

 

      <itemtype code=”ApparelProduct” extends=”Product”>

                          

                           ********

</itemtype>

 

Here ApparalProduct is extending the Product. This is similar to java inheritance concept. The subclass will have all properties of super class. In our case, all the attribute of super class are available for sub class.

  • Ideally we can define an our custom item type, in any extension. But we should define it in relevant extension only.
  • During build of hybris, the extensions are build with taking care of dependency, it makes sure that the parent item type is available.
  • We can control the access to an attribute using modifiers.

<attribute autocreate=“true” qualifier=“code”                     type=“java.lang.String”>

<persistence type=“cmp”             qualifier=“internalCode”/>

<modifiers read=“true” write=“false”   search=“true” initial=“true” optional=“false”            unique=“true”/>

</attribute>

Here the code attribute, is readable, but not writable. It means it’s value cannot be changed, after it is set once.

read – If false, we cannot access it from our java program.

write – If false, we cannot modify the value.

optional– if false, it is mandatory to initialize this attribute. Since it is not optional.

unique– if true, the attribute must hold a unique value. Similar to unique constraints in DBMS.

search – if true, the attribute is searchable through queries.

  • We can control, how the tables are created for an item type. The default table for each item type is genericitem. The table is called as deployment in hybris. So GenericItem is the default deployment.

<deployment table=“UserRights” typecode=“29”/>

Here the table name will be UserRights. The type code is used internally by hybris to generate primary keys. We can give any positive integer for typecode, barring few reserved integers.

  • If we do not give a deployment tag for a item type, the instances of that item type will get start to store in Generic item table. This will cause generic item table to expand drastically, which is a not good for database performance. So we should always give deployment, if our item type is extending generic item directly.
  • Persistence is one of the property of item type attribute. if this property is set to property, it means that attribute will be stored in database. If it is set to dynamic, the attribute will not be part of database table. It is just calculated at run time. This is similar to calculated column in DBMS.

11 thoughts on “Items.xml

  1. Hi anurag , i want to change typecode : 5213 to 25213 , i want to change this in hybris data base(hsql) also , how can i do it , if u have any idea plz suggest me .

    Like

  2. Hi anurag , ur way of explaination is very good , it is easy to learn
    i need a help from u ,i have changed typecode=5132 to 25132 in item.xml , this im not able to do it , actually i have changed and restarted the server and updated in hac , im getting error in command promt that it is” invalid pk 8796093060180 – unknown typecode 5132 ”
    actually what ever we modify that can be changed in data base also but if there is any change in typecode it cannot be modified in data base , it remains same . i have read in hybris wiki also .
    if u have any idea plz suggest me

    Like

  3. @dev, System Initialize requird , once you change at typecode .. that hold the reference of data which they persist at database, after initalization type code will reset for all item.reset the address which pointing before… 🙂

    Like

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s