2

I need to do something like this with JpaRepository:

select * from table
where
(
  propertyTwo like '%something%'
  or propertyThree like '%something%'
  or propertyFour like  '%something%'
)
and propertyOne in (a,b);

I currently do this:

findByPropertyOneInAndPropertyTwoContainingOrPropertyThreeContainingOrPropertyFourContaining(List param1, String param2, String param3, String param4)

But the method do something like this:

select * from table
where
  propertyTwo like '%something%'
  or propertyThree like '%something%'
  or propertyFour like  '%something%'
  and propertyOne in (a,b);

Which is different from the first sql query above.

How can I achieve the correct result?

Mfranco
  • 23
  • 1
  • 4

1 Answers1

0

Like Slava Said, you should do:

@Query("from table t where t.propertyOne in :param1 and (t.propertyTwo like :param2 or t.propertyThree like :param3 or t.propertyFour like :param4)")
List<Table> findByParams(@Param("param1") List<String> param1, @Param("param2") String param2, @Param("param3") String param3, @Param("param4") String param4);
Adrien Colson
  • 649
  • 5
  • 11