Espresso Espresso - 1 year ago 133
Java Question

Spring CrudRepository findByInventoryIds(List<Long> inventoryIdList) - equivalent to IN clause

In Spring CrudRepository, do we have support for "IN clause" for a field? ie something similar to the following?

findByInventoryIds(List<Long> inventoryIdList)

If such support is not available, what elegant options can be considered? Firing queries for each id may not be optimal.

Answer Source

findByInventoryIdIn(List<Long> inventoryIdList) should do the trick.

The HTTP HTTP request parameter format would be like so:

Yes ?id=1,2,3
No  ?id=1&id=2&id=3

The complete list of JPA repository keywords can be found in the current documentation listing. It shows that IsIn is equivalent – if you prefer the verb for readability – and that JPA also supports NotIn and IsNotIn.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download