java - Map primary key composed of two foreign keys? hibernate -
I have 3 class player (PK id_player), match (pk id_match) and inscription (pk to id-player and id_match)
should be there). One player has one and only one inscription (1 player-> 1 record), and one match can be in many inscriptions (1 match -> many reminders), hence the inscriptions in the table have two primary key ID id players and ID_match The problem is, how can I not say in hibernation that both foremost keys must have a textured key for inscription table. This is my code:
@inti @Table (name = "player") public class player {@Id @GeneratedValue Private Long ID_player; @OneToOne @JoinColumn (name = "Pair_ID") inscription recording;} @ Entity @Table (name = "match") public class matching {@Id @GeneratedValue Private Long Id_match; @OneToMany @JoinColumn (name = "id_match") list & lt; Inscription & gt; Inscription = New Arrestist & lt; & Gt; ();
What should I write to become a PP of FK? Thank you
Check this:
Player
< Code> import javax.preistence.Entity; Import javax.preistence.GeneratedValue; Import javax.preistence.Id; Import javax.preistence.OneToOne; Import javax.preistence.Table; @ Entity @Table (name = "player") public class player {@Id @GeneratedValue Private Long ID_player; @OneToOne Private Match Match; }
import java.util.List; Import javax.preistence.Entity; Import javax.preistence.GeneratedValue; Import javax.preistence.Id; Import javax.preistence.JoinColumn; Import javax.preistence.JoinTable; Import javax.preistence.OneToMany; Import javax.preistence.Table; @ Entity @Table (name = "match") public class matching {@Id @GeneratedValue Private Long Id_match; @OneToMany @JoinTable (name = "INSCRIPTION", joinColumns = JoinColumn (name = "MATCH_ID"), inverseJoinColumns = @ JoinColumn (name = "PLAYER_ID")) Private listing & lt; Player & gt; PlayersList; Public long IID_Match () {Return ID_Match; } Public Zero Set ID_match (long id_match) {Id_match = id_match; } Public listing & lt; Player & gt; GetPlayersList () {list of players; } Public Zero set players list (list & gt; player & gt; player list) {this.playersList = playersList; }}
Comments
Post a Comment