2

There are two persistent entities - User and Role. They are mapped by a many-to-many join. The User entity -

@Entity
@Table(name = "users")
@Where( clause=" deletion_date IS NULL ")
public class User extends AbstractEntity {

    private static final long serialVersionUID = 122622094779798680L;

    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinTable(name = "user_role", joinColumns = {
            @JoinColumn(name = "user_uid") },
            inverseJoinColumns = { @JoinColumn(name = "role_id"})

    private List<Role> roles;
    @Id
    @Column(name = "user_uid", unique = true, nullable = false)
    private String userUid;
...

It is an obvious ask to update the set of roles for a user in this schema.

Example - Remove/Add some roles from a user

Addition of roles is fine. But when a deletion of some roles is made to the user entity, the mappings in the join table created by hibernate is not purged.

How to get this purged on role removal?

Rajeev Ranjan
  • 3,588
  • 6
  • 28
  • 52

0 Answers0