javamysqlsap-commerce-cloudcommerce

Hybris - Unable to increase column size in MySql DB


I am trying to increase column size to 1024 characters from default 255 characters. Note that this is an existing production item type(AbstractOrderEntry) & attribute(productDescription). system init is not possbile.

So far I have tried these 2 approaches.

  1. Modified *-items.xml file.

           <attribute qualifier="productDescription" type="java.lang.String">
                <modifiers unique="false" optional="true" read="true" write="true"/>
                <persistence type="property">
                    <columntype database="oracle">
                        <value>varchar(1024)</value>
                    </columntype>
                    <columntype database="sqlserver">
                        <value>nvarchar(1024)</value>
                    </columntype>
                    <columntype database="hsqldb">
                        <value>VARCHAR(1024)</value>
                    </columntype>
                    <columntype>
                        <value>varchar(1024)</value>
                    </columntype>
                </persistence>
            </attribute>
    
  2. ant clean all & system update. Didn't work

Other approach was: Executed alter statement from mySql Workbench.

ALTER TABLE `hybrisDB`.`quoteentries` CHANGE COLUMN `p_productdescription` `p_productdescription` VARCHAR(1024) NULL DEFAULT NULL ;

I could see that column size was increased from SQL workbench. But when I'm trying to save the value from Hybris, It throws runtime exception.

INFO   | jvm 1    | main    | 2019/11/26 14:27:20.262 | com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'p_productdescription' at row 1
INFO   | jvm 1    | main    | 2019/11/26 14:27:20.262 |         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4118)
INFO   | jvm 1    | main    | 2019/11/26 14:27:20.262 |         at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)```


Restarted Hybris after executing direct SQL statement from DB. 

Any other inputs?

Solution

  • I would create a new attribute (in items.xml) with the required size, rebuild and perform a system update, migrate the data from the existing attribute (using ImpEx) and adjust the application code accordingly. It won't be too much effort and it will be the safest thing to do.

    However, if you still want to do it with the existing attribute, please make sure you have backed up your data before performing any of the following things:

    A. Change the items.xml as follows:

    <persistence type="property">
        <columntype database="mysql">
            <value>TEXT</value>
        </columntype>
        <columntype>
            <value>varchar(1024)</value>
        </columntype>
    </persistence>
    

    You have missed to mention database="mysql" in the XML you have posted in the question.

    B. Execute ant clean all updatesystem and test your application.

    C. If it doesn't work, execute the SQL ALTER command you have already done; but this time, make sure to execute system update as well after executing the ALTER command.