0

我有一个 Oracle 18.4.0 XE 数据库,我试图从 JPA 2.1 访问,由 Hibernate 5.2.17 实现。

ManyToMany在 2 个实体之间建立了联系:

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: 上运行 Spring Data JPA 请求时findAllByPermission(Iterable<String> permissions),出现以下异常:

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
4

2 回答 2

6

您正在告诉 Spring Data Jpa 引擎搜索Permission权限等于列表的位置。它应该使用IN运算符,因此您的方法名称应该是:

findAByPermissionIn(Iterable<String> permissions)
于 2019-04-28T15:18:04.763 回答
2

使用“in”关键字:findAllByPermissionIn(Iterable<String> permissions)

这将产生如下查询:where permission0_.permission IN (:permissions).

于 2019-04-28T15:17:06.910 回答