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 in extension

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<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.

About the Author

Karibasappa G C (KB)
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