使用springboot框架,jpa+oracle连接方式,运行查询方法时,出现ORA-00927: 缺失等号

使用springboot框架,jpa+oracle连接方式

代码:

实体类  role.java

@Data
@Entity 
public class Role implements Serializable {
   
    private User createBy;
 

    @ManyToMany(mappedBy = "roles", cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JsonIgnore
    private Set<User> users = new HashSet<>(0);
 
}

实体类  user.java

public class User implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @SequenceGenerator(name = "SEQ_USER_ID", sequenceName =  "SEQ_USER_ID")
    @Excel(value = "用户ID", type = ExcelType.EXPORT)
    private Long id;
  
    @Excel(value = "状态", dict = "DATA_STATUS")
    private Byte status = StatusEnum.OK.getCode();

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id")
    @JsonIgnore
    private Dept dept;

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "sys_user_role",
            joinColumns = @JoinColumn(name = "user_id"),
            inverseJoinColumns = @JoinColumn(name = "role_id"))
    @JsonIgnore
    private Set<Role> roles = new HashSet<>(0);
}

调用方法

@Override
public Boolean existsUserOk(Long id) {
Byte status = StatusEnum.OK.getCode();
return roleRepository.existsByUsers_IdAndStatus(id, status);
}

打印sql如下:
select * from ( select role0_.id as col_0_0_ from sys_role role0_ cross join sys_user_role users1_, sys_user user2_ where ( role0_.status != 3) and role0_.id=users1_.role_id(+) and users1_.user_id=user2_.id(+) and ( user2_.status !(+)= 3) and user2_.id=? and role0_.status=? ) where rownum <= ?
怎么会出现 (+) 这种字符?
 用mysql连接没出现这种问题,换成oracle后出现的。

(+) 是Oracle数据库方言的一种写法,a.id = b.id(+) 就相当于 table a left join table b on a.id = b.id
你目前的问题可能出现在这个地方:user2_.status !(+)= 3 ,(+) 的位置不对,改为:user2_.status(+) != 3


select role0_.id as col_0_0_ from sys_role role0_ left outer join sys_user_role users1_ on role0_.id=users1_.role_id left outer join sys_user user2_ on users1_.user_id=user2_.id and ( user2_.status != 3) where ( role0_.status != 3) and user2_.id=? and role0_.status=? limit 1

这是mysql的连接打印的日志,明显oracle打印出的是乱的

是oracle方言设置的问题,之前用的
hibernate.dialect: org.hibernate.dialect.OracleDialect 这个 ,但是数据库为 11g;

改成
hibernate.dialect: org.hibernate.dialect.Oracle10gDialect
后正常了