spring data jpa 表关联设置用户表关联角色表配置
User 表:
@ManyToMany(cascade = { CascadeType.MERGE }) @JsonIgnore @JoinTable(name = "UserRole", joinColumns = { @JoinColumn(name = "user_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "role_id", referencedColumnName = "id") }) private Collection<Role> roles;
Role表:
@ManyToMany(mappedBy = "roles") @Basic(fetch = FetchType.EAGER) private Collection<User> users;