How to update history variable which is a longstring type variable


#1

How to update history variable which is a longstring type variable。
historicVariableInstanceEntityManager.update(historicVariableInstanceByVariableInstanceId, true);
It will cause this error :Data too long for column ‘TEXT_’ at row 1
Can you give me a solution. Thank you!


#2
import org.flowable.common.engine.impl.interceptor.Command;

import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.variable.api.history.HistoricVariableInstance;
import org.flowable.variable.service.impl.persistence.entity.HistoricVariableInstanceEntity;
import org.flowable.variable.service.impl.persistence.entity.HistoricVariableInstanceEntityManager;
import org.flowable.variable.service.impl.util.CommandContextUtil;

public class SetHistoryVariablesCmd implements Command, Serializable {

private static final long serialVersionUID = 1L;
private HistoricVariableInstance historicVariableInstance;
private String jsonStr;

public SetHistoryVariablesCmd(HistoricVariableInstance historicVariableInstance, String jsonStr) {
    this.historicVariableInstance = historicVariableInstance;
    this.jsonStr = jsonStr;
}

@Override
public Object execute(CommandContext commandContext) {
    HistoricVariableInstanceEntityManager historicVariableInstanceEntityManager
        = CommandContextUtil.getHistoricVariableInstanceEntityManager(commandContext);
    HistoricVariableInstanceEntity historicVariableInstanceByVariableInstanceId = historicVariableInstanceEntityManager
        .findHistoricVariableInstanceByVariableInstanceId(historicVariableInstance.getId());
    historicVariableInstanceByVariableInstanceId.setLastUpdatedTime(new Date());
    if (historicVariableInstanceByVariableInstanceId.getByteArrayRef() != null) {
        // the method set json data into db, but the data charset is error
        historicVariableInstanceByVariableInstanceId.setBytes(jsonStr.getBytes());
    } else {
        historicVariableInstanceByVariableInstanceId.getVariableType();
        historicVariableInstanceByVariableInstanceId.setTextValue(jsonStr);
    }
    historicVariableInstanceEntityManager.update(historicVariableInstanceByVariableInstanceId, false);
    return true;
}

}