Search code examples
mysqljdbcgroup-concatbatch-updates

java.sql.BatchUpdateException: Row x was cut by GROUP_CONCAT()


I have a batch update function which doesn't contain any GROUP_CONCAT() call;

UPDATE 
    product 
SET 
    viewed = ? 
WHERE 
    product_id = ? 

As you see it's a prepared statement. I'm setting its values and then adding it by using addBatch() method foreach row. When my count reaches a defined limit (1000) I'm calling executeBatch() in order to do database modification. As you can see there is no group_concat() calling in my batch update process but mysql jdbc throws this exception. What is the hidden relation with batch update and group_concat() and why? What can I do to resolve this? Decreasing batch limit or increasing group_concat() limit?

My stack trace is;

java.sql.BatchUpdateException: Row 276751 was cut by GROUP_CONCAT()
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2054)
    at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1467)
    at datasource.DB.execPreparedStatement(DB.java:480)
    at datasource.DB.addBatch(DB.java:467)
    at cj.reportsummarydaily.ProductViewed.executeJob(ProductViewed.java:24)
    at job.Job.executeCore(Job.java:101)
    at job.Job.execute(Job.java:77)
    at cj.reportsummarydaily.Main.executeJobMeta(Main.java:35)
    at job.JobMeta.execute(JobMeta.java:32)
    at cronjob.CronJob.main(CronJob.java:66)
Caused by: java.sql.SQLException: Row 276751 was cut by GROUP_CONCAT()
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2006)
    ... 9 more

Solution

  • I found & fixed the problem. One of our ex-programmers had written a faulty before update trigger on table product. So when I was updating product table, trigger was raising that exception on some specific records. I re-programmed correctly the trigger also added below code to increase group_concat limit;

    SET group_concat_max_len=1024 * 10;