many-to-many-relationship between two entities in spring boot
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:
@Entitypublic class Role { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String name; private String description; @ManyToMany(cascade = CascadeType.ALL) @JoinTable private Set<User> users;}
and this:
@Entitypublic 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<Role> roles;}