Reputation: 1
I have entity like that:
@Entity
@Data
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String username;
private String email;
private String password;
}
I want to create table like that:
CREATE TABLE user_to_sub_user (
user_id int,
sub_user_id int
);
which will be showing me users that are sub-users to other users. How can I map this and connect to User using hibernate?
Upvotes: 0
Views: 32
Reputation: 16452
There are plenty of examples online about this kind of mapping. Just search for "Hibernate many to many" and you will find what you are looking for. For example: https://www.baeldung.com/jpa-many-to-many
Upvotes: 1