gpt4 book ai didi

java - 查询id返回类型

转载 作者:行者123 更新时间:2023-11-30 06:27:32 26 4
gpt4 key购买 nike

我使用 Spring 数据。我想从 DB 获得一些契约(Contract)。所以我创建了两个查询。首先我得到了我需要的契约(Contract)ID,第二次我通过这个ID得到了契约(Contract)。

Repository.class 中的第一个查询

@Query(nativeQuery = true, value =
"select id from (" +
"select contract.id, max(invoice.period_to) " +
"from public.invoice " +
"join public.contract on contract.id = invoice.contract_id " +
"where invoice.period_to <= '2017-10-20' " +
"AND contract.close_type IS NULL " +
"AND contract.payment_type != 'TRIAL' " +
"group by contract.id" +
") foo ")
List<Long> findContractsIdForInvoicesCreation();

ServiceJPA.class

List<Long> contractsId = ContractRepository.findContractsIdForInvoicesCreation();
List<Contract> contracts = contractRepository.findAll(contractsId);

但是在上面的最后一行我有一个错误。

java.lang.IllegalArgumentException: Parameter value element [2] did not match expected type [java.lang.Long (n/a)]

如果我只是创建

    List<Long> contractsIdL = new ArrayList<>();
contractsIdL.add(2L);
contractsIdL.add(3L);
contractsIdL.add(4L);
List<Contract> contracts = contractRepository.findAll(contractsId);

一切正常。无法弄清楚出了什么问题。第一次查询返回id是什么类型?

附: DB中的id类型为bigint

p.p.s。我使用 System.out.println 检查了第一个查询 - 它似乎返回了正确的数字。

最佳答案

我认为问题出在 ContractRepository.findContractsIdForInvoicesCreation();

我认为它不会返回List<Long>如你所料

关于java - 查询id返回类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46845952/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com