JPA 2: multiple column usage in foreign keys
You need to do this:
@ManyToOne@JoinColumns({ @JoinColumn(name="gameid", referencedColumnName = "gameid", insertable = false, updatable = false ), @JoinColumn(name="groupTag", referencedColumnName = "grouptag", insertable = false, updatable = false)})private Group group;
EDIT: as mentioned in the comments, @JoinColumn
is a repeatable annotation (since Java 8) that doesn't need wrapping. This simplifies the solution to:
@ManyToOne@JoinColumn(name="gameid", referencedColumnName = "gameid", insertable = false, updatable = false ),@JoinColumn(name="groupTag", referencedColumnName = "grouptag", insertable = false, updatable = false)private Group group;
Are you sure you can't use insertable = false, updateable = false
for these @JoinColumn
s?
As far as I understand, you can initialize gameid
once by setting game
property, and after that you don't need to change it since Tile
s and Group
s belong to the same Game
.