Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collection contains with @Query

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.

like image 908
KenavR Avatar asked Apr 30 '12 08:04

KenavR


1 Answers

Just use the following query and you're done:

@Query("From User u where :role member u.roles")
like image 95
Oleksandr Bondarenko Avatar answered Oct 21 '22 04:10

Oleksandr Bondarenko