Pergunta

Is there a way to use a "contains" function in a @Query tag? If no, what is the best way to implement this?

Example:

@Query("From User u  where u.roles contains :role")
List<User> findByRole(@Param("role") Role role);

The User class does have a Collection containing their Roles.

Edit: As suggested i tried it with like, the application starts, but when this method gets executed a "not matching expected type" exception occurs.

Foi útil?

Solução

Just use the following query and you're done:

@Query("From User u where :role member u.roles")

Outras dicas

Use the like keyword.

@Query("From User u  where u.roles like :role")
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top