我有一个要从JPA 2.1访问的Oracle 18.4.0 XE数据库,该数据库由Hibernate 5.2.17实现。
我在2个实体之间建立了ManyToMany
连接:
public class PermissionEntity implements Serializable {
private static final long serialVersionUID = -3862680194592486778L;
@Id
@GeneratedValue
private Long id;
@Column(unique = true)
private String permission;
@ManyToMany
private List<RoleEntity> roles;
}
public class RoleEntity implements Serializable {
private static final long serialVersionUID = 8037069621015090165L;
@Column(unique = true)
private String name;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "roles")
private List<PermissionEntity> permissions;
}
尝试在PermissionRepository:findAllByPermission(Iterable<String> permissions)
上运行Spring Data JPA请求时,出现以下异常:
Error : 1797, Position : 140, Sql = select permission0_.id as id1_0_, permission0_.permission as permission2_0_ from PermissionEntity permission0_ where permission0_.permission=(:1 , :2 ), OriginalSql = select permission0_.id as id1_0_, permission0_.permission as permission2_0_ from PermissionEntity permission0_ where permission0_.permission=(? , ?), Error Msg = ORA-01797: this operator must be followed by ANY or ALL
答案 0 :(得分:2)
您正在告诉Spring Data Jpa引擎搜索权限等于列表的Permission
。它应使用 IN 运算符,因此您的方法名称应为:
findAByPermissionIn(Iterable<String> permissions)
答案 1 :(得分:1)
使用“ in”关键字:findAllByPermissionIn(Iterable<String> permissions)
。
这将产生如下查询:where permission0_.permission IN (:permissions)
。