我正在处理两个表。我需要从数据库中删除类角色的实体,并且将其链接到“ users_roles”和“ roles_privileges”中。
@Entity
public class User {
@Id
@Column(unique = true, nullable = false)
private String username;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "users_roles", joinColumns = @JoinColumn(name = "user_username", referencedColumnName = "username"), inverseJoinColumns = @JoinColumn(name = "role_entry", referencedColumnName = "entry"))
public Collection<Role> roles;
}
@Entity
public class Role {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long entry;
private String name;
private long project;
@ManyToMany(mappedBy = "roles")
@LazyCollection(LazyCollectionOption.FALSE)
public Collection<User> users;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "roles_privileges",
joinColumns = @JoinColumn(
name = "role_entry", referencedColumnName = "entry"),
inverseJoinColumns = @JoinColumn(
name = "privilege_entry", referencedColumnName = "entry"))
private Collection<Privilege> privileges;
}
使用
roleRepository.delete(role)
我收到“无法删除或更新父行:外键约束失败”。