1

I wanted to pass the collection of String as a step parameter. Since I didn't find a way to construct JobParameter for collection, I decided to pass it as a string with comma-separated values.

My code to execute the job:

@Autowired
private JobLauncher jobLauncher;
@Autowired
private Job myJob;

public void execute() {
    List<String> myCollection = getMyCollection();
    
    jobLauncher.run(myJob, new JobParameters(ImmutableMap.<String, JobParameter> builder()
            .put("myCollection", new JobParameter(String.join(",", myCollection)))
            .build())
    ...
}

I define the Step as follows:

@Bean
@StepScope
public Step myStep(@Value("#{jobParameters['myCollection']}") String myCollectionString) {
    List<String> myCollection = ArrayUtil.asList(lisReferencesString.split(","));
    ...
}

But when execution is started I'm getting the error:

org.postgresql.util.PSQLException: ERROR: value too long for type character varying(250)

Since the job params are stored as a column value, I can't pass too long strings as a param.

Could you suggest how I could overcome it?

androberz
  • 744
  • 10
  • 25

2 Answers2

1

The default length of job parameters of type String is 250, see BATCH_JOB_EXECUTION_PARAMS. The scripts provided by Spring Batch are just a starting point, you can update them as needed. So in your case, you need to increase the length of BATCH_JOB_EXECUTION_PARAMS#STRING_VAL as required.

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50
0

I think there is no way you can pass the collection as job parameter. You can probably

  1. Split the string with 250 characters each and send them in multiple parameters
  2. Save the parameters somewhere in temp table or file and read in the job wherever required.

Please check these threads
how to send a custom object as Job Parameter in Spring Batch?
ArrayList cannot be cast to org.springframework.batch.core.JobParameter

pratap
  • 538
  • 1
  • 5
  • 11