If I understand correctly, what you are actually looking at is a ManyToMany relationship. Many users can use many tags and one cna tag. What bothers you, you are trying to do a JoinTable match as well , instead you can do in your essence:
Tag Element:
@ManyToMany @JoinTable( name = "user_tags", joinColumns = { @JoinColumn(name = "tag_name") }, inverseJoinColumns = { @JoinColumn(name = "user_id") }) private List<User> users= new ArrayList<>();
User object:
@ManyToMany @JoinTable(name = "user_tags", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "tag_name") }) private List<Tag> productionLines = new ArrayList<Tag>();
As you can see, you do not need to deal with the connection table in this case. Maybe I made a typo, so you can find more examples on google or here with the keyword "hibernate ManyToMany JoinTable example"
HRgiger
source share