JPA - using long array in IN operator throws cast exception

百般思念 提交于 2019-12-06 06:09:33

Arrays Long[] and long[] are not valid types of arguments for IN when you want to check against long/Long - only following are:

  • Long
  • long and
  • Collection<Long> (collection_valued_input_parameter)

If you want to stick with JPA and not use org.Hibernate.Query.setParameterList suggested by Kshitij, you have to convert your argument to Collections<Long>.

Conversion is easily done, either by rolling your own or for example with help of ArrayUtil:

long[] id = {1L, 2L};
Long[] longs = ArrayUtils.toObject(id);
Collection<Long> list = Arrays.asList(longs);

try this:

query.setParameterList("id", ids);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!