Monthly Archives: January 2013

Spring batch job – error writing to BATCH_JOB_EXECUTION_CONTEXT

If you ever encounter an error like the following:


Caused by: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [UPDATE BATCH_JOB_EXECUTION_CONTEXT SET SHORT_CONTEXT = ?, SERIALIZED_CONTEXT = ? WHERE JOB_EXECUTION_ID = ?]; SQL state [HY000]; error code [1366]; Incorrect string value: 'xE3x83x9ExE3x83x86...' for column 'SERIALIZED_CONTEXT' at row 1; nested exception is java.sql.SQLException: Incorrect string value: 'xE3x83x9ExE3x83x86...' for column 'SERIALIZED_CONTEXT' at row 1

the character set encoding for the Spring batch tables are wrong. Spring batch default char encoding is latin1. They need to be set to utf8. I followed the approach given at http://docs.moodle.org/23/en/Converting_your_MySQL_database_to_UTF8

Essentially this is all I did:

mysqldump -uusername -ppassword -c -e --default-character-set=utf8 --single-transaction --skip-set-charset --add-drop-database -B jobs > dump.sql
cp dump.sql dump-fixed.sql
vim dump-fixed.sql


:%s/DEFAULT CHARACTER SET latin1/DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci/
:%s/DEFAULT CHARSET=latin1/DEFAULT CHARSET=utf8/
:wq
mysql -uusername -ppassword < dump-fixed.sql