on 07-06-2015 10:03 AM
how to Modif column length from 255 to varchar(4000) in hybris v5.0?
I tried changing the persistence as below, but update didnt help.
<columntype database="oracle">
<value>varchar2(4000)</value>
</columntype>
<columntype database="sqlserver">
<value>nvarchar(max)</value>
</columntype>
<columntype database="mysql">
<value>text</value>
</columntype>
<columntype>
<value>varchar(4000)</value>
</columntype>
</persistence>
I tried with alter table command from sql server and it worked. but this code is already in production and we will not be having access to run alter queries.
Please suggest on how we can fix this issue.
Thanks in advance
Hi,
You can use the below script to update the cloumn size of an existing table.
import de.hybris.platform.core.Registry;
import de.hybris.platform.core.Tenant;
import de.hybris.platform.util.Utilities;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.annotation.Resource;
import javax.sql.DataSource;
Connection conn = null;
PreparedStatement pstmt = null;
try{
final Tenant t = Registry.getCurrentTenant();
conn = t.getDataSource().getConnection();
stmt = conn.prepareStatement("alter table [tableName] alter column [columnName] VARCHAR(5000)");
stmt.execute();
}
catch (final SQLException e){
println("Unable to modify database column!");
println(e.getMessage());
}finally{
Utilities.tryToCloseJDBC(conn, pstmt, null, true);
}
If using MySQL as
a database change the statment as
alter table [tableName] modify column [columnName] VARCHAR(500)
If face any issue try to clear the table data first then run the above script.
I hope this helps!!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks everyone for the replies, we have fixed it by directly altering it from DB using alter query only
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I do not believe this is true. The wiki evens recommends manual updates.
Update will create a table and columns if it not exists. But if the column is already created it will not modify. May be because the tables are not empty.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry to jump-in. Why the update didn't work? Did the DDL generated correctly?
Why altering table manually when items.xml & update system are available? Does this mean that the update system doesn't work?
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
According to this post, when you are changing the size only, the update system will not work. It must be manually done.
https://answers.sap.com/questions/12748769/modifying-column-type-of-existing-attribute-doesnt.html
import groovy.sql.Sql sql = Sql.newInstance("jdbc:oracle:thin:localhost", "username", "password", "oracle.jdbc.driver.DatabaseDriver") sql.execute("alter table XYZTable modify p_name varchar(4000)")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vinay,
You may fix it with the help of interceptors by swapping the (attributes) columns in the back-end as follows:
Create a new attribute with column length as varchar(4000) in items.xml.
Now create a new Prepare interceptor that will intercept this model before saving and save your data in the new attribute instead the attribute in which you were originally saving the data.
Now create another interceptor Load Interceptor that will intercept when this model is loaded. When this model gets loaded copy the value from your new attribute to your old attribute and return the loaded model.
This way for Hybris it would not make any difference but actually you would be swapping values using interceptor.
Regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.