Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn 报错解决

mappedBy与@JoinTable、@JoinColumn互斥

  • 如下代码会产生该错误
@JoinColumn(nullable = false)
@ManyToMany(fetch = FetchType.LAZY,mappedBy = "users", cascade = {CascadeType.REMOVE} )
  • 去掉mappedBy或@JoinTable或@JoinColumn即可解决
@ManyToMany(fetch = FetchType.LAZY,mappedBy = "users", cascade = {CascadeType.REMOVE} )

@ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.REMOVE} )