How to increase the default length of a column in Hybris


I need to increase default length of column defined in Hybris


I need to increase the length of a column called “nickname” defined as part of “MyStoreCustomer” item type

Whenever we define any column as a String type in items.xml, By default Hybris defines max length of column as 255 characters. It means we can insert 255 characters max in that column.

But what if our requirement is to increase default size, let’s say increase to 500 characters ?

In this case, we need to explicitly increase the column size while defining attribute in items.xml

This article is all about how to achieve this.

There are 2 scenarios to achieve the requirement

Scenario 1
We are defining a new attribute and for this new attribute we need to provide max size as 500 characters

Scenario 2
There is already an existing attribute defined either in Hybris OOTB or as part of your project and we need to increase the max size as 

500 for this existing attribute

Let us look at the solution for both the scenarios


In this case, its pretty simple, as we are defining new attribute, we can mention new size of a column using “columntype” as below

  1. <itemtype code="MyStoreCustomer"
  2.                   extends="Customer"
  3.                   jaloclass="com.kb.core.jalo.MyStoreCustomer"
  4.                   autocreate="true"
  5.                   generate="true">
  6.             <attributes>
  8.                  <attribute autocreate="true" qualifier="nickName" type="java.lang.String">
  9.                     <modifiers read="true" write="true" search="true" optional="true"/>
  10.                     <persistence type="property">
  11.                     <columntype>
  12.                             <value>varchar(500)</value>
  13.                     </columntype>
  14.                     </persistence>
  15.                 </attribute>
  17.             </attributes>
  18. </itemtype>
<itemtype code="MyStoreCustomer"
                 <attribute autocreate="true" qualifier="nickName" type="java.lang.String">
                    <modifiers read="true" write="true" search="true" optional="true"/>
                    <persistence type="property">

In this case, we have given the column size as 500.

Just do update system after build, You will be able to see this column with size as 500


This scenario is pretty complex to handle

Reason: Attribute is already defined with default size and it is also persisted in backend

Now Hybris does not allow us to alter its size through items.xml without doing initialization

Then How can we achieve this?

Well, we can still achieve this by following any one of the below 2 options

Option A

Update items.xml as stated in scenario 1 and do initialization

This is probably not a good choice as we can’t take a call for initialization if our project is already delivered to client. We can still do it by taking data backup but not a best choice.

Please avoid initialization as it destroys all the data.

Option B

Configure below code to execute during initialize and update process hook

Check Initialization-and-update-hook-up article for more details to see how to configure below method to execute during Initialization and update system.

  1. public void updateColumnsSize()
  2.     {
  3.         Connection conn = null;
  4.         PreparedStatement pstmt = null;
  5.         try
  6.         {
  7.             conn = Registry.getCurrentTenant().getDataSource().getConnection();
  10.             pstmt = conn.prepareStatement("alter table users alter column nickname varchar(500)");
  11.             pstmt.execute();
  15.         }
  16.         catch (final SQLException e)
  17.         {
  18.             LOG.error("Unable to alter database column!");
  19.         }
  20.         finally
  21.         {
  22.             Utilities.tryToCloseJDBC(conn, pstmt, null);
  23.         }
  24. }
public void updateColumnsSize()
		Connection conn = null;
		PreparedStatement pstmt = null;
			conn = Registry.getCurrentTenant().getDataSource().getConnection();

			pstmt = conn.prepareStatement("alter table users alter column nickname varchar(500)");


		catch (final SQLException e)
			LOG.error("Unable to alter database column!");
			Utilities.tryToCloseJDBC(conn, pstmt, null);


You can load the DB value from property file to see which DB you are connecting to and then modify above code to have if else condition with appropriate query as per the DB configured.

Above query works for Sql Server DB

For MySql DB, query would be as below

  1. alter table users modify column nickname varchar(500)
alter table users modify column nickname varchar(500)

About the Author

Founder of
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

Connect with me on Facebook for more updates

Share this article on