Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data JPA check if a SET contains an object

I have a domain object called Device with this property

@ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
private Set<Driver> authorizedDrivers = new HashSet<>();

I would like to make this query, but I got an error (antlr.NoViableAltException: unexpected AST node: ()

@Query("select dev from Device dev where dev.authorizedDrivers.contains(?1) ")
Set<Device> findDeviceByDriver(Driver driver);
like image 871
Nunyet de Can Calçada Avatar asked Oct 22 '25 17:10

Nunyet de Can Calçada


1 Answers

JPQL does not have 'contains' expression. You can try this query:

@Query("select dev from Device dev join dev.authorizedDrivers d where d = ?1")
Set<Device> findDeviceByDriver(Driver driver);
like image 72
Cepr0 Avatar answered Oct 24 '25 08:10

Cepr0