Hybris data modelling and items.xml

Hybris is data driven architecture, data modelling is backbone of any hybris projects.
Business logic is always located on top of the data model.
To enable data modelling, hybris has provided the concept of items which is same like Objects in java world.

There is dedicated -items.xml file for each extension in hybris.

lets discuss some of the key points about data modelling :
1. What is items.xml.
2. Order of defining tags in items.xml file, why order is necessary ?
3. what is generate attribute and autocreate attribute in itemtype defination.???
4. when to use [ autocreate=”false” generate=”true” ] and [autocreate=”true” generate=”false”]
5. Is it necessary to give deployment table and typecode while defining itemtype??
6. When hybris create database table for an itemtype ?? In ant clean or any other process??

1. What is items.xml.
This is a backbone of the hybris data model.
items.xml is located in the resources directory of an extension.
Every data definitions starts from here.
we can define primitives , objects , relations between objects in this xml file
Each extension has different Items.xml file named as ExtensionName-items.xml
Its not compulsory to have -items.xml file for all extensions.

when we define an item it creates the model class on build of the system code, you can check the generated model class like suppose you have created the Item Stadium then after the build ( i.e . ant all ) it will created the model class as StadiumModel with all getters and setters and other related properties .

every -items.xml file is validated against an items.xsd.

2. Order of defining tags in items.xml file. why order is necessary ?
The order of defining the attributes in the items.xml is as follows :

atomictypes
collectiontypes
enumtypes
maptypes
relations
itemtypes

The -items.xml file is parsed in the single pass hence the order of the tags is important.

3. what is generate attribute and autocreate attribute in itemtype defination.???
generate attribute :
If generate = “true” we tell hybris platform, hey hybris this is new type please generate related classes for this type

if generate=”false” in the itemtype definition then hybris platform understands that its an existing type and he is not instructed to create new classes for this itemtype and updates the existing classes.

Examples :
1. Suppose we are creating new type Company its a standalone itemtype it does not have any parent type then we have to use generate=”true”.

2. Suppose we are creating new type MyProduct with extending product type here we have to use generate=”true” as its a new type to hybris.

3.Suppose you have already created MyProduct type and we want to add few attributes to this type then we have to use generate=”false” here to let hybris know that this type is already created.

autocreate attribute :
If autocreate=”true” then we tell hybris hey hybris this is new type please create its database entries during init/update.

If autocreate=”false” then its indication to hybris that the item is already exist and he is not suppose to create any database entries for this type.

certification/interview question :
* what if we give autocreate=”true” and generate=”false” in item definition ?
It will fail at compile build B’cz every new type in hybris must be first created using generate=true you can do generate= false if you are extending the type with existing definition.

Thumb Rule :
If you are creating the new type or extending the existing type then you have to write generate=”true” and autocreate=”true”. In case of the editing existing type as new item definition we can write generate=”false” and generate=”false”

4. when to use [ autocreate=”false” generate=”true” ] and [autocreate=”true” generate=”false”]
when ItemType is already defined which means autocreate=”false” then as per my understanding  generate=true/false does not has any meaning.
And there will not be any situation where you want to create item but don’t want to create related classes in Hybris. Hence [autocreate=”true” generate=”false”] this is not possible.

5. Is it necessary to give deployment table and typecode while defining itemtype??
The deployment table is optional attribute,If we do not give the deployment table then it will create attributes in genericitems table which is shared by all types without deployment table which will hamper database performance at some point.
If we provide the deployment table then hybris will create dedicated table for the type in database.

The typecode attribute is used internally to form PK for each item of the type.

7)When hybris create database table for an itemtype ?? In ant clean or any other process??
The database table will be created only after updating system.
build , “ant clean” and “ant clean all” does not create database table.Though we successfully build the code.

References :
https://wiki.hybris.com/display/release5/items.xmlquick blogs

 

Leave a Reply

Your email address will not be published. Required fields are marked *