I need to create a join table in my database using JPA
annotations so the result will be this:
I would implement it this way:
@Entity
@Table(name="GROUPS", schema="ADMIN")
public class Group implements Serializable {
@OneToMany
@JoinTable(name = "USER_GROUP",
joinColumns = @JoinColumn(name = "groupid"),
inverseJoinColumns = @JoinColumn(name = "userid"))
private List users;
}
Solution suggested by @PedroKowalski should work too, but then you'll have to keep a reference to Group entity in your User entity which is not always possible.