Spring Batch的`saveAll()`和`save()`方法不起作用,也没有错误。

huangapple go评论70阅读模式
英文:

Spring Batch JPA SaveALL() and SAVE() not working and no Error

问题

I wrote the code, but the jpa is not saved. select statement works but save or saveall doesn't. No way to solve it?

Existing batches except for commercial work well, but only the newly created commercial step does not work.

Below is the corresponding code.

BatchConfiguration.java

@Configuration
@RequiredArgsConstructor
@EnableBatchProcessing
public class BatchConfiguration extends DefaultBatchConfigurer{
  // ... (other beans and configurations)

  @Bean(name = "commercialJob")
  public Job commercialJob() {
    return jobBuilderFactory.get("commercial")
      .incrementer(new RunIdIncrementer())
      .flow(commercialStep())
      .end()
      .build();
  }

  @Bean
  public Step commercialStep() {
    return stepBuilderFactory.get(StepState.COMMERCIAL.toString())
      .<List<AdPoiDto>, List<AdPoiDto>>chunk(CHUNK_SIZE)
      .reader(commercialReader)
      .writer(adpoiWriter)
      .build();
  }

  // ... (other steps and configurations)
}

AdpoiWriter.java

@Slf4j
@RequiredArgsConstructor
@StepScope
@Component
public class AdpoiWriter implements ItemWriter<List<AdPoiDto>>{
  // ... (other fields and methods)

  @Override
  public void write(List<? extends List<AdPoiDto>> adPoiDtos) {
    List<AdPoi> adPoiList = new ArrayList<>();
    ObjectMapper objectMapper = new ObjectMapper();

    for (List<AdPoiDto> dtoList : adPoiDtos) {
      for (AdPoiDto dto : dtoList) {
        AdPoi adPoi = objectMapper.convertValue(dto, AdPoi.class);
        adPoiList.add(adPoi);
      }
    }

    advertisementCommercialRepository.saveAll(adPoiList); // This should save all AdPoi entities
    log.info("@@@ Insert ad_poi End");
  }
}

Based on the provided code, it seems that you have configured a batch job named "commercialJob" with a step named "commercialStep," and within the "commercialStep," you are using the adpoiWriter to save a list of AdPoi entities to the database using advertisementCommercialRepository.saveAll(adPoiList);. If this is not working as expected, here are a few suggestions to check:

  1. Transaction Management: Ensure that the transaction management is correctly set up. You mentioned that you tried using JPATransactionManager but it failed. You need to make sure that the transactions are being managed properly. If there is an issue with transaction management, it could prevent the changes from being persisted in the database.

  2. Error Handling: Check for any error messages or exceptions in your logs. If there is an error during the save operation, it should be logged, and you can investigate the error message to identify the issue.

  3. Database Connection: Ensure that your application has a valid and active database connection. If the connection to the database is lost or not properly configured, it can prevent data from being saved.

  4. Database Configuration: Verify that your database configuration is correct, including the entity mappings and database schema. Ensure that the AdPoi entity is properly annotated with JPA annotations and mapped to the correct database table.

  5. Data Validity: Make sure that the data you are trying to save is valid and does not violate any constraints or validations in your database schema.

  6. QueryDSL: You mentioned that your project uses QueryDSL. Ensure that your QueryDSL queries are correct and not causing any issues with the save operation.

  7. Logging: If you are not seeing any errors in the logs, consider adding additional logging statements to your code to trace the flow of execution and check if the save operation is being reached and if the data being saved is as expected.

Without specific error messages or more detailed information, it's challenging to pinpoint the exact cause of the issue. I recommend reviewing the above points and checking your application logs for any error messages or exceptions that might provide more insights into why the save operation is not working as expected.

英文:

I wrote the code, but the jpa is not saved. select statement works but save or saveall doesn't. No way to solve it?

Existing batches except for commercial work well, but only the newly created commercial step does not work.

Below is the corresponding code.

BatchConfiguration.java

@Configuration
@RequiredArgsConstructor
@EnableBatchProcessing
public class BatchConfiguration extends DefaultBatchConfigurer{

  private final Integer CHUNK_SIZE = 1;

  private final JobBuilderFactory jobBuilderFactory;
  private final StepBuilderFactory stepBuilderFactory;

  // Call Step
  private final CallLogReader callLogReader;
  private final CallLogStatisticsWriter callLogStatisticsWriter;

  // Click Step
  private final ClickLogReader clickLogReader;
  private final ClickLogStatisticsWriter clickLogStatisticsWriter;

  // Exposure Step
  private final ExposureLogReader exposureLogReader;
  private final ExposureAdvertisementLogStatisticsWriter exposureAdvertisementLogStatisticsWriter;
  private final ExposureChannelLogStatisticsWriter exposureChannelLogStatisticsWriter;
  private final ExposureVendorLogStatisticsWriter exposureVendorLogStatisticsWriter;
  private final ExposureLogStatisticsWrtier exposureLogStatisticsWrtier;

  // Search Step
  private final SearchLogReader searchLogReader;
  private final SearchAdministrationLogStatisticsWriter searchAdministrationLogStatisticsWriter;
  private final SearchProspectLogStatisticsWriter searchProspectLogStatisticsWriter;

  // AdvertieseCommercial Step
  private final CommercialReader commercialReader;
  private final AdpoiWriter adpoiWriter;

  // @Autowired(required = true)
  // private JpaTransactionManager transactionManager;

  @Bean(name = &quot;callJob&quot;)
  public Job callJob() {
    return jobBuilderFactory.get(&quot;call&quot;)
        .incrementer(new RunIdIncrementer())
        .flow(callStep())
        .end()
        .build();
  }

  @Bean(name = &quot;clickJob&quot;)
  public Job clickJob() {
    return jobBuilderFactory.get(&quot;click&quot;)
        .incrementer(new RunIdIncrementer())
        .flow(clickStep())
        .end()
        .build();
  }

  @Bean(name = &quot;exposureJob&quot;)
  public Job exposureJob() {
    return jobBuilderFactory.get(&quot;exposure&quot;)
        .incrementer(new RunIdIncrementer())
        .flow(exposureStep())
        .end()
        .build();
  }

  // 가망 통계
  @Bean(name = &quot;searchJob&quot;)
  public Job searchJob() {
    return jobBuilderFactory.get(&quot;search&quot;)
        .incrementer(new RunIdIncrementer())
        .flow(searchStep())
        .end()
        .build();
  }

  //네스 data 저장
  @Bean(name = &quot;commercialJob&quot;)
  public Job commercialJob() {
    return jobBuilderFactory.get(&quot;commercial&quot;)
      .incrementer(new RunIdIncrementer())
      .flow(commercialStep())
      .end()
      .build();
  }


  @Bean
  public Step callStep() {

    return stepBuilderFactory.get(StepState.CALL.toString())
        .&lt;List&lt;CallStatistics&gt;, List&lt;CallStatistics&gt;&gt; chunk(CHUNK_SIZE)
        .reader(callLogReader)
        .writer(callLogStatisticsWriter)
        .build();
  }

  @Bean
  public Step clickStep() {
    
    return stepBuilderFactory.get(StepState.CLICK.toString())
        .&lt;List&lt;ClickStatistics&gt;,List&lt;ClickStatistics&gt;&gt; chunk(CHUNK_SIZE)
        .reader(clickLogReader)
        .writer(clickLogStatisticsWriter)
        .build();
  }

  @Bean
  public Step exposureStep() {

    return stepBuilderFactory.get(StepState.EXPOSURE.toString())
        .&lt;ExposureDto, ExposureDto &gt;chunk(CHUNK_SIZE)
        .reader(exposureLogReader)
        .writer(compositeExposureLogStatisticsWriters())
        .build();
  }

  @Bean
  public Step searchStep() {

    return stepBuilderFactory.get(StepState.SEARCH.toString())
        .&lt;SearchDto, SearchDto &gt;chunk(CHUNK_SIZE)
        .reader(searchLogReader)
        .writer(compositeSearchLogStatisticsWriters())
        .build();
  }

  @Bean
  public Step commercialStep() {

    return stepBuilderFactory.get(StepState.COMMERCIAL.toString())
      .&lt;List&lt;AdPoiDto&gt;, List&lt;AdPoiDto&gt;&gt;chunk(CHUNK_SIZE)
      .reader(commercialReader)
      .writer(adpoiWriter)
      // .transactionManager(transactionManager)
      .build();
  }

  @Bean
  public CompositeItemWriter&lt;ExposureDto&gt; compositeExposureLogStatisticsWriters() {
    CompositeItemWriter&lt;ExposureDto&gt; compositeItemWriter = new CompositeItemWriter&lt;&gt;();
    compositeItemWriter.setDelegates(Arrays.asList(exposureAdvertisementLogStatisticsWriter,
        exposureChannelLogStatisticsWriter, exposureLogStatisticsWrtier, exposureVendorLogStatisticsWriter));

    return compositeItemWriter;
  }

  @Bean
  public CompositeItemWriter&lt;SearchDto&gt; compositeSearchLogStatisticsWriters() {
    CompositeItemWriter&lt;SearchDto&gt; compositeItemWriter = new CompositeItemWriter&lt;&gt;();
    compositeItemWriter.setDelegates(Arrays.asList(searchAdministrationLogStatisticsWriter,
        searchProspectLogStatisticsWriter));

    return compositeItemWriter;
  }
}

writer

@Slf4j
@RequiredArgsConstructor
@StepScope
@Component
public class AdpoiWriter implements ItemWriter&lt;List&lt;AdPoiDto&gt;&gt;{

  @Autowired
  private final AdvertisementCommercialRepository advertisementCommercialRepository;

  @Override
  public void write(List&lt;? extends List&lt;AdPoiDto&gt;&gt; adPoiDtos) {
    List&lt;AdPoi&gt; adPoiList = new ArrayList&lt;&gt;();
    ObjectMapper objectMapper = new ObjectMapper();

    for (List&lt;AdPoiDto&gt; dtoList : adPoiDtos) {

      for (AdPoiDto dto : dtoList) {
        AdPoi adPoi = objectMapper.convertValue(dto, AdPoi.class);
        adPoiList.add(adPoi);
      }

    }

    // AdPoi adPoi = new AdPoi();
    // System.out.println(&quot;@@@@ : Adpoi :  &quot; + adPoiList.get(0));
    // advertisementCommercialRepository.save(adPoi);
    // advertisementCommercialRepository.insertData(adPoiList.get(0).getOp_cl(), adPoiList.get(0).getTelno_cl());
    advertisementCommercialRepository.saveAll(adPoiList);
    // Iterable&lt;AdPoi&gt; adPois = advertisementCommercialRepository.findAll();
    // for (AdPoi adPoi : adPois) {
    //   System.out.println(&quot;@@@ 11234&quot; + adPoi.toString());
    // }
    log.info(&quot;@@@ Insert ad_poi End&quot;);
    
  }
    
}

Terminal log that appears when the batch is executed

2023-06-22 10:22:58.213  INFO 23995 --- [nio-8084-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet &#39;dispatcherServlet&#39;
2023-06-22 10:22:58.214  INFO 23995 --- [nio-8084-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet &#39;dispatcherServlet&#39;
2023-06-22 10:22:58.274  INFO 23995 --- [nio-8084-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 60 ms
@@@@ 2023-06-21
2023-06-22 10:22:58.579 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:22:58.581 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?]
2023-06-22 10:22:58.673 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:22:58.674 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?]
2023-06-22 10:22:58.693 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:22:58.693 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?]
2023-06-22 10:22:58.769 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:22:58.775 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [INSERT into BATCH_JOB_INSTANCE(JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (?, ?, ?, ?)]
2023-06-22 10:22:58.841 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:22:58.842 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [INSERT into BATCH_JOB_EXECUTION(JOB_EXECUTION_ID, JOB_INSTANCE_ID, START_TIME, END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, VERSION, CREATE_TIME, LAST_UPDATED, JOB_CONFIGURATION_LOCATION) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
2023-06-22 10:22:58.865 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:22:58.872 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [INSERT into BATCH_JOB_EXECUTION_PARAMS(JOB_EXECUTION_ID, KEY_NAME, TYPE_CD, STRING_VAL, DATE_VAL, LONG_VAL, DOUBLE_VAL, IDENTIFYING) values (?, ?, ?, ?, ?, ?, ?, ?)]
2023-06-22 10:22:58.910 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:22:58.911 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [INSERT INTO BATCH_JOB_EXECUTION_CONTEXT (SHORT_CONTEXT, SERIALIZED_CONTEXT, JOB_EXECUTION_ID) VALUES(?, ?, ?)]
2023-06-22 10:22:58.959  INFO 23995 --- [ryBean_Worker-1] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=commercial]] launched with the following parameters: [{TIME=1687310578370}]
2023-06-22 10:22:58.998 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:22:58.998 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT VERSION FROM BATCH_JOB_EXECUTION WHERE JOB_EXECUTION_ID=?]
2023-06-22 10:22:59.019 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:22:59.019 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT COUNT(*) FROM BATCH_JOB_EXECUTION WHERE JOB_EXECUTION_ID = ?]
2023-06-22 10:22:59.037 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:22:59.039 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [UPDATE BATCH_JOB_EXECUTION set START_TIME = ?, END_TIME = ?,  STATUS = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = ?, CREATE_TIME = ?, LAST_UPDATED = ? where JOB_EXECUTION_ID = ? and VERSION = ?]
2023-06-22 10:22:59.093 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:22:59.093 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, CREATE_TIME, LAST_UPDATED, VERSION, JOB_CONFIGURATION_LOCATION from BATCH_JOB_EXECUTION where JOB_INSTANCE_ID = ? order by JOB_EXECUTION_ID desc]
2023-06-22 10:22:59.103 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:22:59.103 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT JOB_EXECUTION_ID, KEY_NAME, TYPE_CD, STRING_VAL, DATE_VAL, LONG_VAL, DOUBLE_VAL, IDENTIFYING from BATCH_JOB_EXECUTION_PARAMS where JOB_EXECUTION_ID = ?]
2023-06-22 10:22:59.136 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:22:59.136 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT STEP_EXECUTION_ID, STEP_NAME, START_TIME, END_TIME, STATUS, COMMIT_COUNT, READ_COUNT, FILTER_COUNT, WRITE_COUNT, EXIT_CODE, EXIT_MESSAGE, READ_SKIP_COUNT, WRITE_SKIP_COUNT, PROCESS_SKIP_COUNT, ROLLBACK_COUNT, LAST_UPDATED, VERSION from BATCH_STEP_EXECUTION where JOB_EXECUTION_ID = ? order by STEP_EXECUTION_ID]
2023-06-22 10:22:59.186 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:22:59.186 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT  SE.STEP_EXECUTION_ID, SE.STEP_NAME, SE.START_TIME, SE.END_TIME, SE.STATUS, SE.COMMIT_COUNT, SE.READ_COUNT, SE.FILTER_COUNT, SE.WRITE_COUNT, SE.EXIT_CODE, SE.EXIT_MESSAGE, SE.READ_SKIP_COUNT, SE.WRITE_SKIP_COUNT, SE.PROCESS_SKIP_COUNT, SE.ROLLBACK_COUNT, SE.LAST_UPDATED, SE.VERSION, JE.JOB_EXECUTION_ID, JE.START_TIME, JE.END_TIME, JE.STATUS, JE.EXIT_CODE, JE.EXIT_MESSAGE, JE.CREATE_TIME, JE.LAST_UPDATED, JE.VERSION from BATCH_JOB_EXECUTION JE, BATCH_STEP_EXECUTION SE where       SE.JOB_EXECUTION_ID in (SELECT JOB_EXECUTION_ID from BATCH_JOB_EXECUTION where JOB_INSTANCE_ID = ?)      and SE.JOB_EXECUTION_ID = JE.JOB_EXECUTION_ID       and SE.STEP_NAME = ? order by SE.START_TIME desc, SE.STEP_EXECUTION_ID desc]
2023-06-22 10:22:59.236 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:22:59.236 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, CREATE_TIME, LAST_UPDATED, VERSION, JOB_CONFIGURATION_LOCATION from BATCH_JOB_EXECUTION where JOB_INSTANCE_ID = ? order by JOB_EXECUTION_ID desc]
2023-06-22 10:22:59.245 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:22:59.245 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT JOB_EXECUTION_ID, KEY_NAME, TYPE_CD, STRING_VAL, DATE_VAL, LONG_VAL, DOUBLE_VAL, IDENTIFYING from BATCH_JOB_EXECUTION_PARAMS where JOB_EXECUTION_ID = ?]
2023-06-22 10:22:59.273 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:22:59.273 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT STEP_EXECUTION_ID, STEP_NAME, START_TIME, END_TIME, STATUS, COMMIT_COUNT, READ_COUNT, FILTER_COUNT, WRITE_COUNT, EXIT_CODE, EXIT_MESSAGE, READ_SKIP_COUNT, WRITE_SKIP_COUNT, PROCESS_SKIP_COUNT, ROLLBACK_COUNT, LAST_UPDATED, VERSION from BATCH_STEP_EXECUTION where JOB_EXECUTION_ID = ? order by STEP_EXECUTION_ID]
2023-06-22 10:22:59.371 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:22:59.371 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [INSERT into BATCH_STEP_EXECUTION(STEP_EXECUTION_ID, VERSION, STEP_NAME, JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, COMMIT_COUNT, READ_COUNT, FILTER_COUNT, WRITE_COUNT, EXIT_CODE, EXIT_MESSAGE, READ_SKIP_COUNT, WRITE_SKIP_COUNT, PROCESS_SKIP_COUNT, ROLLBACK_COUNT, LAST_UPDATED) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
2023-06-22 10:22:59.394 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:22:59.395 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [INSERT INTO BATCH_STEP_EXECUTION_CONTEXT (SHORT_CONTEXT, SERIALIZED_CONTEXT, STEP_EXECUTION_ID) VALUES(?, ?, ?)]
2023-06-22 10:22:59.431  INFO 23995 --- [ryBean_Worker-1] o.s.batch.core.job.SimpleStepHandler     : Executing step: [COMMERCIAL]
2023-06-22 10:22:59.439 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:22:59.439 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [UPDATE BATCH_STEP_EXECUTION set START_TIME = ?, END_TIME = ?, STATUS = ?, COMMIT_COUNT = ?, READ_COUNT = ?, FILTER_COUNT = ?, WRITE_COUNT = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = ?, READ_SKIP_COUNT = ?, PROCESS_SKIP_COUNT = ?, WRITE_SKIP_COUNT = ?, ROLLBACK_COUNT = ?, LAST_UPDATED = ? where STEP_EXECUTION_ID = ? and VERSION = ?]
2023-06-22 10:22:59.456 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:22:59.456 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT VERSION FROM BATCH_JOB_EXECUTION WHERE JOB_EXECUTION_ID=?]
2023-06-22 10:22:59.554 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:22:59.554 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [UPDATE BATCH_STEP_EXECUTION_CONTEXT SET SHORT_CONTEXT = ?, SERIALIZED_CONTEXT = ? WHERE STEP_EXECUTION_ID = ?]
2023-06-22 10:22:59.626  INFO 23995 --- [ryBean_Worker-1] c.z.w.m.b.s.c.CommercialReader           : Commercial Batch START
2023-06-22 10:22:59.626  INFO 23995 --- [ryBean_Worker-1] c.z.w.m.b.s.c.CommercialReader           : Commercial STEP DATE : 2023-06-21
2023-06-22 10:23:00.408  INFO 23995 --- [ryBean_Worker-1] c.z.w.m.b.s.c.c.AdpoiWriter              : @@@ Insert ad_poi End
2023-06-22 10:23:00.413 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:23:00.413 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [UPDATE BATCH_STEP_EXECUTION_CONTEXT SET SHORT_CONTEXT = ?, SERIALIZED_CONTEXT = ? WHERE STEP_EXECUTION_ID = ?]
2023-06-22 10:23:00.436 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:23:00.436 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [UPDATE BATCH_STEP_EXECUTION set START_TIME = ?, END_TIME = ?, STATUS = ?, COMMIT_COUNT = ?, READ_COUNT = ?, FILTER_COUNT = ?, WRITE_COUNT = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = ?, READ_SKIP_COUNT = ?, PROCESS_SKIP_COUNT = ?, WRITE_SKIP_COUNT = ?, ROLLBACK_COUNT = ?, LAST_UPDATED = ? where STEP_EXECUTION_ID = ? and VERSION = ?]
2023-06-22 10:23:00.454 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:23:00.454 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT VERSION FROM BATCH_JOB_EXECUTION WHERE JOB_EXECUTION_ID=?]
2023-06-22 10:23:00.502  INFO 23995 --- [ryBean_Worker-1] c.z.w.m.b.s.c.CommercialReader           : Commercial Batch START
2023-06-22 10:23:00.502  INFO 23995 --- [ryBean_Worker-1] c.z.w.m.b.s.c.CommercialReader           : Commercial STEP DATE : 2023-06-21
2023-06-22 10:23:00.502 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:23:00.502 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [UPDATE BATCH_STEP_EXECUTION_CONTEXT SET SHORT_CONTEXT = ?, SERIALIZED_CONTEXT = ? WHERE STEP_EXECUTION_ID = ?]
2023-06-22 10:23:00.520 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:23:00.521 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [UPDATE BATCH_STEP_EXECUTION set START_TIME = ?, END_TIME = ?, STATUS = ?, COMMIT_COUNT = ?, READ_COUNT = ?, FILTER_COUNT = ?, WRITE_COUNT = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = ?, READ_SKIP_COUNT = ?, PROCESS_SKIP_COUNT = ?, WRITE_SKIP_COUNT = ?, ROLLBACK_COUNT = ?, LAST_UPDATED = ? where STEP_EXECUTION_ID = ? and VERSION = ?]
2023-06-22 10:23:00.537 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:23:00.538 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT VERSION FROM BATCH_JOB_EXECUTION WHERE JOB_EXECUTION_ID=?]
2023-06-22 10:23:00.587 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:23:00.587 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [UPDATE BATCH_STEP_EXECUTION_CONTEXT SET SHORT_CONTEXT = ?, SERIALIZED_CONTEXT = ? WHERE STEP_EXECUTION_ID = ?]
2023-06-22 10:23:00.619  INFO 23995 --- [ryBean_Worker-1] o.s.batch.core.step.AbstractStep         : Step: [COMMERCIAL] executed in 1s188ms
2023-06-22 10:23:00.627 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:23:00.627 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [UPDATE BATCH_STEP_EXECUTION set START_TIME = ?, END_TIME = ?, STATUS = ?, COMMIT_COUNT = ?, READ_COUNT = ?, FILTER_COUNT = ?, WRITE_COUNT = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = ?, READ_SKIP_COUNT = ?, PROCESS_SKIP_COUNT = ?, WRITE_SKIP_COUNT = ?, ROLLBACK_COUNT = ?, LAST_UPDATED = ? where STEP_EXECUTION_ID = ? and VERSION = ?]
2023-06-22 10:23:00.645 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:23:00.645 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT VERSION FROM BATCH_JOB_EXECUTION WHERE JOB_EXECUTION_ID=?]
2023-06-22 10:23:00.692 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:23:00.692 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [UPDATE BATCH_JOB_EXECUTION_CONTEXT SET SHORT_CONTEXT = ?, SERIALIZED_CONTEXT = ? WHERE JOB_EXECUTION_ID = ?]
2023-06-22 10:23:00.740 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:23:00.741 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT VERSION FROM BATCH_JOB_EXECUTION WHERE JOB_EXECUTION_ID=?]
2023-06-22 10:23:00.760 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
2023-06-22 10:23:00.760 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT COUNT(*) FROM BATCH_JOB_EXECUTION WHERE JOB_EXECUTION_ID = ?]
2023-06-22 10:23:00.777 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update
2023-06-22 10:23:00.777 DEBUG 23995 --- [ryBean_Worker-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [UPDATE BATCH_JOB_EXECUTION set START_TIME = ?, END_TIME = ?,  STATUS = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = ?, CREATE_TIME = ?, LAST_UPDATED = ? where JOB_EXECUTION_ID = ? and VERSION = ?]
2023-06-22 10:23:00.817  INFO 23995 --- [ryBean_Worker-1] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=commercial]] completed with the following parameters: [{TIME=1687310578370}] and the following status: [COMPLETED] in 1s743ms
2023-06-22 10:23:00.818  INFO 23995 --- [ryBean_Worker-1] c.z.w.m.b.q.QuartzJobLauncher            : Status : COMPLETED

DB uses only one instance,
There are no newly overridden methods in the Repository.

It's not a project I made, it's a module pattern project, and this project uses querydsl. Maybe it has something to do with why querydsl doesn't work?

I tried using JPATransactionManager as well, but it failed.

Hope jpa save() or saveall() will work

答案1

得分: 0

你需要使用 JpaTransactionManager,但你说过 我也尝试使用 JPATransactionManager,但失败了。

你没有分享你如何尝试的细节,但由于你的类扩展了 DefaultBatchConfigurer,期望是你要覆盖 getTransactionManager 方法并返回一个 JpaTransactionManager

英文:

You need to use a JpaTransactionManager, but you said I tried using JPATransactionManager as well, but it failed.

You did not share how you tried that, but since your class extends DefaultBatchConfigurer, the expectation is that you override the getTransacctionManager method and return a JpaTransactionManager.

答案2

得分: 0

感谢Mahmoud Ben Hassine的回答,我通过添加以下代码来解决了这个问题:

@Autowired
private final DataSource dataSource;

@Autowired
private final EntityManagerFactory entityManagerFactory;

@Override
public PlatformTransactionManager getTransactionManager() {
  return new JpaTransactionManager(entityManagerFactory);
}
英文:

Thanks to Mahmoud Ben Hassine's answer, I solved it by adding that code.

@Autowired
private final DataSource dataSource;
@Autowired
private final EntityManagerFactory entityManagerFactory;
@Override
public PlatformTransactionManager getTransactionManager() {
return new JpaTransactionManager(entityManagerFactory);
}

huangapple
  • 本文由 发表于 2023年6月22日 09:32:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76528117.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定