【发布时间】:2018-09-07 22:46:45
【问题描述】:
我正在使用 Spring Boot + Spring Batch + Spring JPA Data,我正在尝试使用 Spring Batch 中的RepositoryItemReader。
批处理对于提供方法(没有 nativeQuery)工作正常,但我在尝试原生查询时遇到了这个问题。
问题总是返回一个空数组(行数始终为 0)。
以下是控制台日志:
Hibernate: SELECT * FROM QUOTE_OFFER_FULFILLMENT QOF WHERE QOF.STATUS=? OR QOF.STATUS=?
#pageable
order by QOF.id desc limit ?
[DEBUG] org.hibernate.loader.Loader - bindNamedParameters() FULFILLMENT_READY -> 1 [1]
[DEBUG] org.hibernate.loader.Loader - bindNamedParameters() FAILED -> 2 [2]
[DEBUG] org.hibernate.stat.internal.ConcurrentStatisticsImpl - HHH000117: HQL: SELECT * FROM QUOTE_OFFER_FULFILLMENT QOF WHERE QOF.STATUS=? OR QOF.STATUS=?
#pageable
order by QOF.id desc, time: 1ms, rows: 0
[DEBUG] org.hibernate.engine.transaction.internal.TransactionImpl - committing
我的存储库方法:
@Component
@Repository
public interface QuoteOfferFulfillmentRepository
extends JpaRepository<QuoteOfferFulfillment, Long> {
@query(value = "SELECT * FROM QUOTE_OFFER_FULFILLMENT QOF WHERE QOF.STATUS=?1 OR QOF.STATUS=?2 \n#pageable\n", nativeQuery = true)
Page findTempByStatus(QuoteOfferFulfillmentStatus status,
QuoteOfferFulfillmentStatus status1, Pageable pageable);
}
还有我的 BatchConfiguration:
@Bean
public RepositoryItemReader reader() {
RepositoryItemReader fullfillment = new RepositoryItemReader();
fullfillment.setRepository(fulfillmentRepository);
fullfillment.setMethodName("findTempByStatus");
List list = new ArrayList();
list.add(QuoteOfferFulfillmentStatus.FULFILLMENT_READY);
list.add(QuoteOfferFulfillmentStatus.FAILED);
fullfillment.setPageSize(40);
fullfillment.setArguments(list);
HashMap<String, Direction> sorts = new HashMap<>();
sorts.put("id", Direction.DESC);
fullfillment.setSort(sorts);
return fullfillment;
}
谁能建议我做错了什么?
【问题讨论】:
标签: spring spring-boot spring-batch