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.

  1. <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:

  1. <itemtype code="PaymentInfo"
  2.                   extends="GenericItem"
  3.                   jaloclass="de.hybris.platform.jalo.order.payment.PaymentInfo"
  4.                   autocreate="true"
  5.                   generate="true">
<itemtype code="PaymentInfo"
                  extends="GenericItem"
                  jaloclass="de.hybris.platform.jalo.order.payment.PaymentInfo"
                  autocreate="true"
                  generate="true">

is same as

  1. <itemtype code="PaymentInfo” jaloclass="de.hybris.platform.jalo.order.payment.PaymentInfo"
  2.                  autocreate="true"
  3.                  generate="true">
<itemtype code="PaymentInfo” jaloclass="de.hybris.platform.jalo.order.payment.PaymentInfo"
                  autocreate="true"
                  generate="true">


When we should define deployment mandatorily?

We should define deployment for an item type in the following scenarios

1) Defining new item type by extending GenericItem
Example:

  1. <itemtype code="Unit"
  2.                   extends="GenericItem"
  3.                   jaloclass="de.hybris.platform.jalo.product.Unit"
  4.                   autocreate="true"
  5.                   generate="true">
  6.             <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:

  1. <itemtype code="AbstractOrder"
  2.                   extends="GenericItem"
  3.                   jaloclass="de.hybris.platform.jalo.order.AbstractOrder"
  4.                   autocreate="true"
  5.                   generate="true"
  6.                   abstract="true">
  7. <itemtype code="Cart"
  8.                   extends="AbstractOrder"
  9.                   jaloclass="de.hybris.platform.jalo.order.Cart"
  10.                   autocreate="true"
  11.                   generate="true">
  12.             <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

  1. 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:

  1. <itemtype code="Product"
  2.                   extends="GenericItem"
  3.                   jaloclass="de.hybris.platform.jalo.product.Product"
  4.                   autocreate="true"
  5.                   generate="true">
  6.             <deployment table="Products" typecode="1"/>
  7.  
  8. <itemtype code="ApparelProduct" extends="Product"
  9.                 autocreate="true" generate="true" jaloclass="org.training.core.jalo.ApparelProduct">
  10.                 <description>Base apparel product extension that contains additional attributes.</description>
  11.                 <attributes>
  12.                     <attribute qualifier="genders" type="GenderList">
  13.                         <description>List of genders that the ApparelProduct is designed for</description>
  14.                         <modifiers />
  15.                         <persistence type="property" />
  16.                     </attribute>
  17.                 </attributes>
  18.             </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.

About the Author

Founder of javainsimpleway.com
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to kb.knowledge.sharing@gmail.com

Connect with me on Facebook for more updates

Share this article on