Overview of items.xml file
Items.xml file contains the type definition in hybris.
We can define the new item types, extend the existing item types in the items.xml file
Items.xml file is located in the resources directory of an extension as below
Items.xml file names are prefixed with respective extension name.
Example:
In core extension, it is available as core-items.xml file.
In trainingcore extension, it is available as trainingcore-items.xml file.
The basic structure of items.xml is as below
- <items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:noNamespaceSchemaLocation="items.xsd">
- <atomictypes>
- ...
- </atomictypes>
- <collectiontypes>
- ...
- </collectiontypes>
- <enumtypes>
- ...
- </enumtypes>
- <maptypes>
- ...
- </maptypes>
- <relations>
- ...
- </relations>
- <itemtypes>
- ...
- </itemtypes>
- </items>
<items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="items.xsd"> <atomictypes> ... </atomictypes> <collectiontypes> ... </collectiontypes> <enumtypes> ... </enumtypes> <maptypes> ... </maptypes> <relations> ... </relations> <itemtypes> ... </itemtypes> </items>
Items.xml file is always validated against items.xsd.
Items.xsd file has defined the order in which the elements have to be defined in items.xml file.
Hence we have to maintain the above order of elements in items.xml file.
Note:
If we do not maintain the above order in items.xml file, build will be failed.
Defining new item type
we can define new item type in items.xml file using code ,deployment and all the attributes for that item type.
- <itemtype code="SampleType1"
- extends="GenericItem"
- autocreate="true"
- generate="true">
- <deployment table="SampleType1" typecode="11000"/>
- <attributes>
- <attribute>
- ………
- </attribute>
- <attribute>
- ………
- </attribute>
- <attribute>
- ………
- </attribute>
- </attributes>
- </itemtype>
- <itemtype code="SampleType2"
- extends="SampleType1"
- autocreate="true"
- generate="true">
- <deployment table="SampleType2" typecode="11001"/>
- <attributes>
- <attribute>
- ………
- </attribute>
- <attribute>
- ………
- </attribute>
- <attribute>
- ………
- </attribute>
- </attributes>
- </itemtype>
<itemtype code="SampleType1" extends="GenericItem" autocreate="true" generate="true"> <deployment table="SampleType1" typecode="11000"/> <attributes> <attribute> ……… </attribute> <attribute> ……… </attribute> <attribute> ……… </attribute> </attributes> </itemtype> <itemtype code="SampleType2" extends="SampleType1" autocreate="true" generate="true"> <deployment table="SampleType2" typecode="11001"/> <attributes> <attribute> ……… </attribute> <attribute> ……… </attribute> <attribute> ……… </attribute> </attributes> </itemtype>
We have defined 2 item types SampleType1 and SampleType2
Where SampleType2 is extending SampleType1
Order of Item Types in items.xml
Items.xml file is evaluated in one pass unlike impex which is multi pass processed.
Because of single pass,we need to specify the item types in the order of inheritance.
More abstract types has to be defined at the beginning of the items.xml file
More concrete types has to be defined at the end of the items.xml file
If we reverse the above item type definition as below, build will fail.
- <itemtype code="SampleType2"
- extends="SampleType1"
- autocreate="true"
- generate="true">
- <deployment table="SampleType2" typecode="11001"/>
- <attributes>
- <attribute>
- ………
- </attribute>
- <attribute>
- ………
- </attribute>
- <attribute>
- ………
- </attribute>
- </attributes>
- </itemtype>
- <itemtype code="SampleType1"
- extends="GenericItem"
- autocreate="true"
- generate="true">
- <deployment table="SampleType1" typecode="11000"/>
- <attributes>
- <attribute>
- ………
- </attribute>
- <attribute>
- ………
- </attribute>
- <attribute>
- ………
- </attribute>
- </attributes>
- </itemtype>
<itemtype code="SampleType2" extends="SampleType1" autocreate="true" generate="true"> <deployment table="SampleType2" typecode="11001"/> <attributes> <attribute> ……… </attribute> <attribute> ……… </attribute> <attribute> ……… </attribute> </attributes> </itemtype> <itemtype code="SampleType1" extends="GenericItem" autocreate="true" generate="true"> <deployment table="SampleType1" typecode="11000"/> <attributes> <attribute> ……… </attribute> <attribute> ……… </attribute> <attribute> ……… </attribute> </attributes> </itemtype>
Since SampleType2 is more concrete than SampleType1, SampleType1 has to appear before the SampleType2 in the items.xml file.
Classes generated after build
1) Generated*.java source files for all item types of an extension to the gensrc directory of your extension.
2) *Model.java model classes for all item types of an extension to the bootstrap/gensrc directory
where * has to be replaced with item type code.
for item type SampleType1, GeneratedSampleType1.java and SampleType1Model.java files are generated once the build is done.
Note:
After build,only java changes will reflect but DB changes in Hybris for the new item type will be reflected only after Initialization or Update.
how does the complier know the custom types defined in collectiontype and relation type which are placed on top of items.xml while the new custom types are just added to itemtyes when the items.xml is single pass?
Hi Sir,
can you write a article on Cart and checkout process in Hybris, Please
Thank you
SampleType1 and SampleType2 cannot have the same typecode.
Please correct it.
yes you are right. above example is not about deployment code, so did not emphasize it, anyway updated it. Thanks
Please check below article for deployment and typecodes in details
http://javainsimpleway.com/deployment-and-typecodes-in-items-xml/
Hi KB,
Will you explain about single pass and multi pass in hybris? why we specifiying that items.xml is single pass and ImpEx is Multipass..
if you are using the same deployment code for two item types, build will fail.
yes you are right. above example is not about deployment code, so did not emphasize it.
Please check below article for that
http://javainsimpleway.com/deployment-and-typecodes-in-items-xml/
What is the main purpose for using atomictype in item.xml because we don’t use any unique identifier. How it is useful?
can we create custom AtomicTypes in items.xml ?
if yes explain?
if no Why?
Karibasappa G C (KB) Very Nice Artice.
It is very Usefull to every one
What exactly is the purpose of the Generated*.java source files? And the bootstrap folder you’ve mentioned here is the one that is present in the ‘platform’ ?
Its used internally by hybris , we dont use it.
Yes Platform bootstrap only