BNR
BNR

Reputation: 89

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?

Upvotes: 1

Views: 3077

Answers (3)

Arvind Kumar Avinash
Arvind Kumar Avinash

Reputation: 79035

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.

Upvotes: 0

www.hybriscx.com
www.hybriscx.com

Reputation: 1129

In your question, you mentioned 2 approaches. I think you can manage to achieve your objective by combining both the approaches i.e.,

  1. Modify $exntesion-items.xml --> ant clean all --> ant updatesystem
  2. Run alter statement on database directly and start Hybris

Related : An excerpt from sap wiki :

enter image description here

Reference : help.sap.com

Upvotes: 1

Joe Sebin
Joe Sebin

Reputation: 450

You can try to redeclare the attribute.

 <attribute qualifier="productDescription" redeclare="true" type="java.lang.String">
   <modifiers read="true" write="true" optional="true" unique="false" />
     <persistence type="property">
      <columntype>
          <value>HYBRIS.LONG_STRING</value>
      </columntype>
     </persistence>
</attribute>

Upvotes: 0

Related Questions