I have two Entities in my Spring-Boot Application:
User.java
@Entity
public class User {
@Id
@GeneratedValue(strategy =
You can find any tutorial connected with many-to-many relationship using Hibernate/Spring Data, example: Spring Data many-to-many
With your model it's simple to add the relationship mappings, like this:
@Entity
public class Role {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String description;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable
private Set users;
}
and this:
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String firstname;
private String lastname;
private String username;
private String password;
@ManyToMany(mappedBy = "users")
private Set roles;
}