Explain Core concept of autocreate and generate in hybris items | items concept in hybris?


Clear Concept about autocreate and generate in Hybris item
In many time hybris developer become confuse or not able to give clear answer related autocreate and generate in hybris item.

So today I have decided to go with autocreate and generate
I know every hybris developer who started reading this post they will think that I know but let’s check your concept with my scenario

1. What meaning of autocreate and generate
Answer: as per hybris wiki autocreate means make database entry during initialization and update for this item and generate is responsible to create generated java class and jalo class
2. So my second question is what is meaning of database entry for autocreate
   

   suppose your item is             

  <itemtype code="EveryreplyCustTest2" generate="false" autocreate="false">
                   <description>It represents everyreply Customer.</description>
                   <attributes>
                       <attribute qualifier="customerId" type="java.lang.String" >
                    <persistence type="property" />
                   <description>It is localized customerId of the everyreply user.</description>
                 </attribute>
                  </attributes>
    </itemtype>   

If you give autocreate="false" then it will give Build error means you are restricting to create model class then there is no any meaning of this item in hybris because defining items means data model then
Why it autocreate given in Hybris while must have to create model class?
Because sometime you extending Items then at time you are doing something on existing model class then there is not require to create model class again so that’s why Hybris given attribute autocreate on Item definition level


Now again autocreate comes under to define attribute level also as below            

<attributes>
<attribute qualifier="customerId" type="java.lang.String" autocreate="true">
<persistence type="property" />
<description>It is localized customerId of the everyreply user.</description>
 </attribute>

 In above autocreate follow same rule as Item level definition but for this it will follow rule inside your Model class if it is false then this attribute will missing in your model class
3. Now comes to use Generate in Items level and Attribute definition level
Generate is responsible to create jalo class and generated class in extension. If you give generate="false" then after build there will create jalo class and generated class in your extension.
 
 


<itemtype code="EveryreplyUserTest1"  autocreate="true" generate="false" >
<description>Apparel size variant type that contains additional attribute describing variant size.</description>
     <attributes>
          <attribute qualifier="userid" type="java.lang.String">
          <description>Size of the product.</description>
                        <modifiers initial="true" write="false"/>
                        <persistence type="property"/>
                    </attribute>
                </attributes>
            </itemtype>

If you give generate="false" and given jaloclass as below



<itemtype code="EveryreplyUserTest1"  autocreate="true" generate="false" jaloclass="de.hybris.platform.yacceleratorcore.jalo.EveryreplyUserTest1" >
                <description>Apparel size variant type that contains additional attribute describing variant size.</description>
                <attributes>
                <attribute qualifier="userid" type="java.lang.String">
                        <description>Size of the product.</description>
                        <modifiers initial="true" write="false"/>
                        <persistence type="property"/>
                    </attribute>
                </attributes>
            </itemtype>
 

 Then it give build error
In attribute level Generate="true" is responsible for creating setter and getter inside the model class. As you there another modifier used in attribute
   <modifiers write="true" read="true"/>


It is responsible for creating setter and getter inside the model class then definitely in your mind question is coming that why used generate while read and write is responsible for setter and getter so below combination will make you ok

   A. generate="false" and in modifier read="true" write="true" > build error
   B. generate="true" and in modifier read="false" write="true" > only setter will create
   C. generate="true" and in modifier read="true" write="false" > only getter is      create

 

4 comments:

  1. your english is not understandable

    ReplyDelete
  2. Hello friend,

    Thanks for sharing your knowledge. However, I fell that you should work on your English. I was only able to understand 50% of what you said.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Thanks For the info but you should read your blog just after writing it and before posting it. I see some mistakes which might create trouble for beginner.

    ReplyDelete