Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring RepositoryItemReader nativeQuery_Spring_Spring Boot_Spring Batch - Fatal编程技术网

Spring RepositoryItemReader nativeQuery

Spring RepositoryItemReader nativeQuery,spring,spring-boot,spring-batch,Spring,Spring Boot,Spring Batch,我正在使用SpringBoot+SpringBatch+SpringJPA数据,并且我正在尝试使用SpringBatch中的RepositoryItemReader 对于没有nativeQuery的给定方法,批处理工作正常,但我在尝试使用本机查询时遇到了这个问题 问题是它总是返回一个空数组行计数总是0 以下是控制台日志: Hibernate: SELECT * FROM QUOTE_OFFER_FULFILLMENT QOF WHERE QOF.STATUS=? OR QOF.STATUS=?

我正在使用SpringBoot+SpringBatch+SpringJPA数据,并且我正在尝试使用SpringBatch中的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);
}
以及我的批处理配置:

@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;
}
有人能指出我做错了什么吗?

您需要在native@Query中添加countQuery参数来定义页面的大小

从:

SpringDataJPA目前不支持本机数据的动态排序 查询,因为它必须操作实际的查询 声明,对于本机SQL它无法可靠地执行此操作。你可以, 但是,请通过指定计数来使用本机查询进行分页 查询您自己,如下例所示:

编辑


您好@gustavo Passini,感谢您的回复。根据您的建议,以下是更改,@Queryvalue=SELECT*FROM QUOTE\u OFFER\u FULFILLMENT QOF,其中QOF.STATUS=?1或QOF.STATUS=?2\n可编辑\n,countQuery=SELECT count*FROM offers.QUOTE\u FULFILLMENT QOF,其中QOF.STATUS=?1或QOF.STATUS=?2,nativeQuery=true Page findtempyStatus quoteofferfulfillmentstatus STATUS,QuoteOfferFulfillmentStatus Status 1,可分页可分页;但是没有运气。这是同样的结果。正在将结果获取为0。我做错什么了吗?@Balakrishna Tirumalasetti,你好。不客气。对不起,我看不出问题出在哪里。我已经将一个最简单的工作示例上传到我的Github。我希望它能帮助你。
public interface UserRepository extends JpaRepository<User, Long> {

  @Query(value = "SELECT * FROM USERS WHERE LASTNAME = ?1",
    countQuery = "SELECT count(*) FROM USERS WHERE LASTNAME = ?1",
    nativeQuery = true)
  Page<User> findByLastname(String lastname, Pageable pageable);
}