kkkjjjkj 2022-02-16 14:45 采纳率: 0%
浏览 72

使用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后出现的。

  • 写回答

3条回答 默认 最新

  • IT阿沈 2022-02-16 15:11
    关注

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

    评论

报告相同问题?

问题事件

  • 创建了问题 2月16日

悬赏问题

  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效