title: Hibernate embedded key with another Entity and a field
body: <p>I can't find a concrete and COMPLETE example of what I'm looking for.</p>
  
  <p>In my case, I have the entities 'Game' and 'GameCodeColor'.
  The PK of Game is an int Id.
  The PK of GameCodeColor should be a 'Game' and an integer. But at line:</p>
  
  <pre><code>sessionFactory =  new AnnotationConfiguration().configure().buildSessionFactory();
  </code></pre>
  
  <p>I keep getting:</p>
  
  <pre><code>"Unable to find properties (Game, GameCodeColorIndex) in entity annotated with @IdClass:h.GameCodeColor"
  </code></pre>
  
  <p>Here are the codes I have so far:
  GameCodeColorPK</p>
  
  <pre><code>package h;
  
  import javax.persistence.*;
  import java.io.*;
  
  @Embeddable
  public class GameCodeColorPK implements Serializable {
  
      @OneToOne
      @JoinColumn(name = "gc_g_Id", referencedColumnName = "g_Id")
      protected Game Game;
      @Basic
      @Column(name = "gc_Index")
      protected int GameCodeColorIndex;
  
      public GameCodeColorPK() {
      }
  
      public GameCodeColorPK(Game Game, int GameCodeColorIndex) {
          this.Game = Game;
          this.GameCodeColorIndex = GameCodeColorIndex;
      }
  
      @Override
      public boolean equals(Object obj) {
          if (obj == null) {
              return false;
          }
          if (getClass() != obj.getClass()) {
              return false;
          }
          final GameCodeColorPK other = (GameCodeColorPK) obj;
          if (this.Game != other.Game &amp;&amp; (this.Game == null || !this.Game.equals(other.Game))) {
              return false;
          }
          if (this.GameCodeColorIndex != other.GameCodeColorIndex) {
              return false;
          }
          return true;
      }
  
      @Override
      public int hashCode() {
          int hash = 7;
          hash = 71 * hash + (this.Game != null ? this.Game.hashCode() : 0);
          hash = 71 * hash + this.GameCodeColorIndex;
          return hash;
      }
  }
  </code></pre>
  
  <p>GameCodeColor</p>
  
  <pre><code>package h;
  
  import javax.persistence.*;
  import java.io.*;
  
  @Entity
  @Table(name = "GameCodeColors")
  @IdClass(GameCodeColorPK.class)
  public class GameCodeColor implements Serializable {
  
      @EmbeddedId
      private GameCodeColorPK GameCodeColorPK;
  
      public GameCodeColor() {
      }
  
      public h.GameCodeColorPK getGameCodeColorPK() {
          return GameCodeColorPK;
      }
  
      public void setGameCodeColorPK(h.GameCodeColorPK GameCodeColorPK) {
          this.GameCodeColorPK = GameCodeColorPK;
      }
      @Basic
      @Column(name = "gcode_gc_Index")
      private int GameColorIndex;
  
      public int getGameColorIndex() {
          return GameColorIndex;
      }
  
      public void setGameColorIndex(int GameColorIndex) {
          this.GameColorIndex = GameColorIndex;
      }
  
      public GameCodeColor(h.GameCodeColorPK GameCodeColorPK, int GameColorIndex) {
          this.GameCodeColorPK = GameCodeColorPK;
          this.GameColorIndex = GameColorIndex;
      }
  }
  </code></pre>
  
  <p>Game</p>
  
  <pre><code>package h;
  
  import java.io.*;
  import javax.persistence.*;
  import java.util.*;
  
  @Entity
  @Table(name = "Games")
  public class Game implements Serializable {
  
      public Game() {
      }
  
      public Set&lt;GameCodeColor&gt; getGameCodeColors() {
          return GameCodeColors;
      }
  
      public void setGameCodeColors(Set&lt;GameCodeColor&gt; GameCodeColors) {
          this.GameCodeColors = GameCodeColors;
      }
  
      public Set&lt;GameColor&gt; getGameColors() {
          return GameColors;
      }
  
      public void setGameColors(Set&lt;GameColor&gt; GameColors) {
          this.GameColors = GameColors;
      }
  
      public Set&lt;GameTurn&gt; getGameTurns() {
          return GameTurns;
      }
  
      public void setGameTurns(Set&lt;GameTurn&gt; GameTurns) {
          this.GameTurns = GameTurns;
      }
  
      public Game(h.User User, Date StartTime, Date EndTime, int TurnsPlayed, int TurnsToBePlayed, int CodeLength, int AvailableColoursCount, int ResetCount, boolean DoubleAllowed, int GameResult_Id) {
          this.User = User;
          this.StartTime = StartTime;
          this.EndTime = EndTime;
          this.TurnsPlayed = TurnsPlayed;
          this.TurnsToBePlayed = TurnsToBePlayed;
          this.CodeLength = CodeLength;
          this.AvailableColoursCount = AvailableColoursCount;
          this.ResetCount = ResetCount;
          this.DoubleAllowed = DoubleAllowed;
          this.GameResult_Id = GameResult_Id;
      }
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "g_Id")
      private int Id;
  
      public int getId() {
          return Id;
      }
      @ManyToOne
      @JoinColumn(name = "g_u_Id")
      private User User;
  
      public h.User getUser() {
          return User;
      }
  
      public void setUser(h.User User) {
          this.User = User;
      }
      @Temporal(TemporalType.TIMESTAMP)
      @Column(name = "g_StartTime")
      private java.util.Date StartTime;
  
      public java.util.Date getStartTime() {
          return StartTime;
      }
  
      public void setStartTime(java.util.Date StartTime) {
          this.StartTime = StartTime;
      }
      @Temporal(TemporalType.TIMESTAMP)
      @Column(name = "g_EndTime")
      private java.util.Date EndTime;
  
      public java.util.Date getEndTime() {
          return EndTime;
      }
  
      public void setEndTime(java.util.Date EndTime) {
          this.EndTime = EndTime;
      }
      @Basic
      @Column(name = "g_TurnsPlayed")
      private int TurnsPlayed;
      @Basic
      @Column(name = "g_TurnsToBePlayed")
      private int TurnsToBePlayed;
      @Basic
      @Column(name = "g_CodeLength")
      private int CodeLength;
      @Basic
      @Column(name = "g_AvailableColoursCount")
      private int AvailableColoursCount;
      @Basic
      @Column(name = "g_ResetCount")
      private int ResetCount;
      @Basic
      @Column(name = "g_doubleAllowed")
      private boolean DoubleAllowed;
      @Basic
      @Column(name = "g_gr_Id")
      private int GameResult_Id;
  
      public int getAvailableColoursCount() {
          return AvailableColoursCount;
      }
  
      public void setAvailableColoursCount(int AvailableColoursCount) {
          this.AvailableColoursCount = AvailableColoursCount;
      }
  
      public int getCodeLength() {
          return CodeLength;
      }
  
      public void setCodeLength(int CodeLength) {
          this.CodeLength = CodeLength;
      }
  
      public boolean isDoubleAllowed() {
          return DoubleAllowed;
      }
  
      public void setDoubleAllowed(boolean DoubleAllowed) {
          this.DoubleAllowed = DoubleAllowed;
      }
  
      public int isGameResult_Id() {
          return GameResult_Id;
      }
  
      public void setGameResult_Id(int GameResult_Id) {
          this.GameResult_Id = GameResult_Id;
      }
  
      public int getResetCount() {
          return ResetCount;
      }
  
      public void setResetCount(int ResetCount) {
          this.ResetCount = ResetCount;
      }
  
      public int getTurnsPlayed() {
          return TurnsPlayed;
      }
  
      public void setTurnsPlayed(int TurnsPlayed) {
          this.TurnsPlayed = TurnsPlayed;
      }
  
      public int getTurnsToBePlayed() {
          return TurnsToBePlayed;
      }
  
      public void setTurnsToBePlayed(int TurnsToBePlayed) {
          this.TurnsToBePlayed = TurnsToBePlayed;
      }
  
      @Override
      public boolean equals(Object obj) {
          if (obj == null) {
              return false;
          }
          if (getClass() != obj.getClass()) {
              return false;
          }
          final Game other = (Game) obj;
          if (this.Id != other.Id) {
              return false;
          }
          return true;
      }
  
      @Override
      public int hashCode() {
          int hash = 5;
          hash = 37 * hash + this.Id;
          return hash;
      }
      @OneToMany(mappedBy = "GameTurn")
      private Set&lt;GameTurn&gt; GameTurns = new HashSet&lt;GameTurn&gt;();
  
      public GameTurn addNewGameTurn(java.util.Date DateTime, int Correct, int Misplaced, boolean IsWon) {
          GameTurn result = new GameTurn(
                  this,
                  this.GameTurns != null ? this.GameTurns.size() : 0,
                  DateTime,
                  Correct,
                  Misplaced,
                  IsWon);
  
          this.GameTurns.add(result);
          return result;
      }
      @OneToMany(mappedBy = "GameColor")
      private Set&lt;GameColor&gt; GameColors = new HashSet&lt;GameColor&gt;();
  
      public void addNewGameColor(int RGBvalue) {
          GameColor gc = new GameColor();
          gc.setGame(this);
          gc.setGameColorIndex(this.GameColors != null ? this.GameColors.size() : 0);
          gc.setRGBvalue(RGBvalue);
          this.GameColors.add(gc);
      }
      @OneToMany(mappedBy = "GameCodeColor")
      private Set&lt;GameCodeColor&gt; GameCodeColors = new HashSet&lt;GameCodeColor&gt;();
  
      public void addGameCodeColor(int GameColorIndex) {
  //            this.GameCodeColors.add(new GameCodeColor(
  //                    this,
  //                    this.GameCodeColors != null ? this.GameCodeColors.size() : 0,
  //                    GameColorIndex));
      }
  
      public int getGameResult_Id() {
          return GameResult_Id;
      }
  
      public void setId(int Id) {
          this.Id = Id;
      }
  
      public Game(int Id, h.User User, Date StartTime, Date EndTime, int TurnsPlayed, int TurnsToBePlayed, int CodeLength, int AvailableColoursCount, int ResetCount, boolean DoubleAllowed, int GameResult_Id) {
          this.Id = Id;
          this.User = User;
          this.StartTime = StartTime;
          this.EndTime = EndTime;
          this.TurnsPlayed = TurnsPlayed;
          this.TurnsToBePlayed = TurnsToBePlayed;
          this.CodeLength = CodeLength;
          this.AvailableColoursCount = AvailableColoursCount;
          this.ResetCount = ResetCount;
          this.DoubleAllowed = DoubleAllowed;
          this.GameResult_Id = GameResult_Id;
      }
  }
  </code></pre>