2017-10-20 124 views
1

我使用彈簧數據。我想從DB獲得一些合約。所以我創建了兩個querys。在第一我得到合同身份證,我需要,第二我通過這個ID得到合同。在Repository.class查詢ID返回類型

首先查詢

@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

但在最後一行上面我有一個錯誤。

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?

p.s. DB中的id類型是bigint

p.p.s我用System.out.println檢查了第一個查詢 - 它似乎返回了corect數字。

+0

檢查是什麼在數組中。猜猜其中一個值是不是長(例如null) – StanislavL

+0

我通過System.Out.Println cheked了 - 顯示[2,3,4] - 實際上我需要 –

+0

它可能是id值不是長整型但例如整數。你可能需要設置結果類 – StanislavL

回答

1

我認爲這個問題是ContractRepository.findContractsIdForInvoicesCreation();

我認爲它不會返回List<Long>如你預期

+0

你完全正確。它返回BigInteger,不長。 –