0
votes

"In clause" not working on passing multiple values

Repository code

@Query( "select myObject from MyObject myObject where myObject.anyColumn in :values" )
public List<MyObject> findPriDestByCntryAbbr(@Param("values") List<String> values);

Calling from service

List<String> values = Arrays.asList(valuesString.split(","));
List<MyObject> result = myObjectRepository.findByAnyColumns(values);

When i am passing single value it is retrieving correct information from table, But on passing multiple values in List "values" giving empty result

1
Did you check the content of the values variable ?davidxxx
Yes, I did 'values ' are correctRaj N

1 Answers

0
votes

Ideally it should work. You should check the values variable.

The other way you can try is- without writing query. As per the doc we can create MyObjectRepository interface by extending Repository interface and then have a method to fetch all MyObjects. It goes like:

public interface MyObjectRepository extends Repository<MyObject,**Long**> {

List<MyObject> findBy**AnyColumn**In(Collection<String> values);

}

"AnyColumn" is your column name and second parameter for Repository interface is as per your requirement.