Spring Data JPA检查SET是否包含对象

时间:2018-01-23 15:00:37

标签: java jpa spring-boot spring-data object-persistence

我有一个名为Device的域对象,具有此属性

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

我想进行此查询,但我收到错误(antlr.NoViableAltException:意外AST节点:()

@Query("select dev from Device dev where dev.authorizedDrivers.contains(?1) ")
Set<Device> findDeviceByDriver(Driver driver);

1 个答案:

答案 0 :(得分:1)

JPQL没有&#39;包含&#39;表达。您可以尝试此查询:

@Query("select dev from Device dev join dev.authorizedDrivers d where d = ?1")
Set<Device> findDeviceByDriver(Driver driver);