所以我有IDS春數據JPA的findAll(可迭代<ID> IDS)不允許重複的ID
List<Integer> ids = [1,1,1,5];
的列表,當我通過該列表findAll(Iterable<ID> ids)
的 而不是返回4個實體,它會只返回ID爲1,5的2。
有什麼方法可以改變findAll(),所以它不會刪除重複項?
所以我有IDS春數據JPA的findAll(可迭代<ID> IDS)不允許重複的ID
List<Integer> ids = [1,1,1,5];
的列表,當我通過該列表findAll(Iterable<ID> ids)
的 而不是返回4個實體,它會只返回ID爲1,5的2。
有什麼方法可以改變findAll(),所以它不會刪除重複項?
我不認爲這是可能的:SELECT * FROM foo WHERE id in (1, 1, 1, 5)
也將返回2行,而不是4.它不是爲您創建克隆對象的存儲庫作業。如果您需要克隆實體,只需創建一個clone method/copy constructor。
可以後的findAll完成重建這個名單,這裏是代碼:
List<Integer> ids = [1,1,1,5];
List<Foo> fooList = fooDao.findAll(ids); // Only two objects
List<Foo> newFooList = new ArrayList<>();
for (Integer id : ids) {
Foo f; // Find the object from the origin list using `CollectionUtils` etc.
newFooList.add(f);
}
只是好奇,爲什麼不從原來的列表中刪除重複的? – dic19
只因爲我需要多個相同的實體進行一些計算 – user3691923
你確定'ids'列表代表你的PK嗎? –