0

I have two table with Many to Many relationship

Table 1           Table 2          Junction Table
---Game---      ---Player---      ---GamePlayer---
gameID(PK)      playerID(PK)      gameID
gameDetails     playerDetails     playerID 
                                  PK(gameID,playerID)

I have one more table "Setting"

Table 
---Setting---
settingID
settingName
settingValue
FK(gameID,PlayerID)

which have relation with Game and Player in way that

  • A player can have number of settings for each game.

I dont know how to implement this in hibernate.

Apologies if this is a simple fix. I am new to the hibernate. Some help or better solution would be greatly appreciated.

1 Answers1

0

For setting you can define entity as follows:

@Entity
public class Setting{
    ...
    @ManyToOne
    private Game game;
    @ManyToOne
    private Player player;
    ...
}

and if you want to have a list of settings of a player you can define in Player object:

@Entity
public class Setting{
    ...
    @OneToMany(mappedBy="player")
    private List<Setting> settings;
}
Dandelion
  • 744
  • 2
  • 13
  • 34