I want to create a composite key in follower table, only two columns in the table with the Id's of the users. Right now I have my follower table with the two foreign keys and the id of the table
How can I make this possible since all the examples that I find are from two different tables?
[This is the approach that I have right now]

[This is the one that I want]

Followers table
public class Followers {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private long id;
@ManyToOne
@JoinColumn(name="from_user_fk")
private User from;
@ManyToOne
@JoinColumn(name="to_user_fk")
private User to;
public Followers() {};
public Followers(User from, User to) {
this.from = from;
this.to = to;
}
}
User table
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
private String lastname;
public User() {
}
@OneToMany(mappedBy="to")
private List<Followers> followers;
@OneToMany(mappedBy="from")
private List<Followers> following;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
}