Deployment and Typecodes in items.xml
We know that in Hybris items can be persisted in database.
It means they will be stored in the tables.
So we need to specify the table name while defining the item type so that the values of the item type will be persisted in that table.
This process of defining the table for the item type in items.xml is called deployment.
Each instances of an item type is stored as one row in the table.
In Deployment tag we specify table name and typecode as below.
- <deployment table="MyContactInfo" typecode="12000"/>
<deployment table="MyContactInfo" typecode="12000"/>
Table name and typecode should be unique globally.
Typecode value should be greater than 10000 and less than 32767.
Typecode is used during the PK generation mechanism and hence it should be unique
Typecode values between 0 & 10000 are reserved by Hybris
Deployment inheritance from a type to its subtypes
If we don’t specify the deployment for any of our item type then deployment specified in the closest type in the hierarchy will be considered.
If there is no hierarchy which means if the item type is not extending any item type then by default GenericItem will be considered as the parent of the item type.
And hence the deployment of GenericItem will be used by the item type.
So all the instances of this item type will be stored in the GenericItem table
We can also extend GenericItem for our item type however it will be extended by default if item type is not specified with any parent type.
It’s same as Object class for all the java classes.
Example:
- <itemtype code="PaymentInfo"
- extends="GenericItem"
- jaloclass="de.hybris.platform.jalo.order.payment.PaymentInfo"
- autocreate="true"
- generate="true">
<itemtype code="PaymentInfo" extends="GenericItem" jaloclass="de.hybris.platform.jalo.order.payment.PaymentInfo" autocreate="true" generate="true">
is same as
- <itemtype code="PaymentInfo” jaloclass="de.hybris.platform.jalo.order.payment.PaymentInfo"
- autocreate="true"
- generate="true">
<itemtype code="PaymentInfo” jaloclass="de.hybris.platform.jalo.order.payment.PaymentInfo" autocreate="true" generate="true">
When we should define deployment mandatorily?
1) Defining new item type by extending GenericItem
Example:
- <itemtype code="Unit"
- extends="GenericItem"
- jaloclass="de.hybris.platform.jalo.product.Unit"
- autocreate="true"
- generate="true">
- <deployment table="Units" typecode="10"/>
<itemtype code="Unit" extends="GenericItem" jaloclass="de.hybris.platform.jalo.product.Unit" autocreate="true" generate="true"> <deployment table="Units" typecode="10"/>
2)Defining new item type by extending existing item type for which there is no deployment
Example:
- <itemtype code="AbstractOrder"
- extends="GenericItem"
- jaloclass="de.hybris.platform.jalo.order.AbstractOrder"
- autocreate="true"
- generate="true"
- abstract="true">
- <itemtype code="Cart"
- extends="AbstractOrder"
- jaloclass="de.hybris.platform.jalo.order.Cart"
- autocreate="true"
- generate="true">
- <deployment table="Carts" typecode="43"/>
<itemtype code="AbstractOrder" extends="GenericItem" jaloclass="de.hybris.platform.jalo.order.AbstractOrder" autocreate="true" generate="true" abstract="true"> <itemtype code="Cart" extends="AbstractOrder" jaloclass="de.hybris.platform.jalo.order.Cart" autocreate="true" generate="true"> <deployment table="Carts" typecode="43"/>
deployment is not defined for AbstractOrder as its abstract type,Cart is extending AbstractOrder , so deployment must be defined for Cart.
Note:
1) If we don’t specify deployment for the above scenarios then build will fail.
If we want to pass the build and let items to be stored in GenericItem table then define below property in the local.properties file
- build.development.mode=false
build.development.mode=false
This is not advisable because storing many item types in GenericItem table will decrease the performance and possibility of data truncation due to columns limit in the table.
2)Deployment table should not be defined for any Item type if there is already a deployment defined for its super type otherwise it will decrease the performance as it has to perform multiple joins while retrieving.
Example:
- <itemtype code="Product"
- extends="GenericItem"
- jaloclass="de.hybris.platform.jalo.product.Product"
- autocreate="true"
- generate="true">
- <deployment table="Products" typecode="1"/>
- <itemtype code="ApparelProduct" extends="Product"
- autocreate="true" generate="true" jaloclass="org.training.core.jalo.ApparelProduct">
- <description>Base apparel product extension that contains additional attributes.</description>
- <attributes>
- <attribute qualifier="genders" type="GenderList">
- <description>List of genders that the ApparelProduct is designed for</description>
- <modifiers />
- <persistence type="property" />
- </attribute>
- </attributes>
- </itemtype>
<itemtype code="Product" extends="GenericItem" jaloclass="de.hybris.platform.jalo.product.Product" autocreate="true" generate="true"> <deployment table="Products" typecode="1"/> <itemtype code="ApparelProduct" extends="Product" autocreate="true" generate="true" jaloclass="org.training.core.jalo.ApparelProduct"> <description>Base apparel product extension that contains additional attributes.</description> <attributes> <attribute qualifier="genders" type="GenderList"> <description>List of genders that the ApparelProduct is designed for</description> <modifiers /> <persistence type="property" /> </attribute> </attributes> </itemtype>
In this case Its not advisable to specify the deployment for ApparelProduct as it is extending Product and Product has the deployment defined already.
I have seen below typecode ranges
0-10099,
13200-13299,
24400-24599 and
32700-32799
are reserved for internal Hybris’ use and must not be used to avoid
conflicts with new Hybris out-of-the-box extensions in multiple articles.
But most of them says only from 0 – 10k are reserved for Hybris OOTB.
Your website is awesome, it helps a lot at the time of learning hybris as well as working on project. Please prepare a article on Hot Folder.
Hi Sir,
What is “Jalo class” attribute? what is its usage ?
Regards,
Viswanth.
If there is no deployment specified for ApparelProduct, then where will the ‘genders’ attribute of ApparelProduct be stored in database?
It will be saved as a new column in the parent type,in this case it will be saved in products table
Then what is the need of defining new item type if we are deploying in the same database?
You can load only required types in your application using flexible search query rather than loading everything of that table.
What is the maximum length of above table name?
Hi KB,
Nice explanation, it is useful to everyone.
Thank you Shankar !!
It is grate website to learn many technology easily. I am injoying to learn Hybris. Please prepare a article on Hot Folder.