title: Hibernate many-to-many relation inside ternary relation
body: <p>to-Many relation between the two table <code>User</code> and <code>Reservation</code>, So I have this new table <code>InternalParticipant</code></p>
  
  <pre><code>@Entity
  @Table(name = "user_has_reservation")
  @AssociationOverrides({
      @AssociationOverride(name = "pk.user", 
          joinColumns = @JoinColumn(name = "uhr_idUser")),
      @AssociationOverride(name = "pk.reservation", 
          joinColumns = @JoinColumn(name = "uhr_idReservation")) })
  public class InternalParticipant implements java.io.Serializable {
  
      private static final long serialVersionUID = 1L;
      private InternalParticipantId pk = new InternalParticipantId();
  
      @JsonIgnore
      private Set&lt;UserAccessReservation&gt; userAccessReservations = new HashSet&lt;UserAccessReservation&gt;(0);
  
      @EmbeddedId
      public InternalParticipantId getPk() {
          return this.pk;
      }
  
      public void setPk(InternalParticipantId pk) {
          this.pk = pk;
      }
  
      @Transient
      public User getUser() {
          return getPk().getUser();
      }
  
      public void setUser(User user) {
          getPk().setUser(user);
      }
  
      @Transient
      public Reservation getReservation() {
          return getPk().getReservation();
      }
  
      public void setReservation(Reservation reservation) {
          getPk().setReservation(reservation);
      }
  
      @OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.internalParticipant")
      public Set&lt;UserAccessReservation&gt; getUserAccessReservations() {
          return this.userAccessReservations;
      }
  
      public void setUserAccessReservations(Set&lt;UserAccessReservation&gt; userAccessReservations) {
          this.userAccessReservations = userAccessReservations;
      }
  }
  </code></pre>
  
  <p>and the Id:</p>
  
  <pre><code>@Embeddable
  public class InternalParticipantId implements java.io.Serializable {
  
      private static final long serialVersionUID = 1L;
      private User user;
      private Reservation reservation;
  
      @ManyToOne
      public User getUser() {
          return this.user;
      }
  
      public void setUser(User user) {
          this.user = user;
      }
  
      @ManyToOne
      public Reservation getReservation() {
          return this.reservation;
      }
  
      public void setReservation(Reservation reservation) {
          this.reservation = reservation;
      }
  }
  </code></pre>
  
  <p>Now I have to link this table in a ternary relation with <code>Day</code> and <code>Time</code> so I crate a new Table with the 4 primary key:</p>
  
  <pre><code>@Entity
  @Table(name = "user_access_reservation")
  @AssociationOverrides({
      @AssociationOverride(name = "pk.internalParticipant.pk.user", joinColumns = @JoinColumn(name = "uar_idUser")),
      @AssociationOverride(name = "pk.internalParticipant.pk.reservation", joinColumns = @JoinColumn(name = "uar_idReservation")),
      @AssociationOverride(name = "pk.time", joinColumns = @JoinColumn(name = "uar_idTime")),
      @AssociationOverride(name = "pk.day", joinColumns = @JoinColumn(name = "uar_idDay"))})
  public class UserAccessReservation implements java.io.Serializable {
  
      private static final long serialVersionUID = 1L;
      private UserAccessReservationId pk = new UserAccessReservationId();
  
      @EmbeddedId
      public UserAccessReservationId getPk() {
          return this.pk;
      }
  
      public void setPk(UserAccessReservationId pk) {
          this.pk = pk;
      }
  
      @Transient
      public InternalParticipant getInternalParticipant() {
          return getPk().getInternalParticipant();
      }
  
      public void setInternalParticipant(InternalParticipant internalParticipant) {
          getPk().setInternalParticipant(internalParticipant);
      }
  
      @Transient
      public Time getTime() {
          return getPk().getTime();
      }
  
      public void setTime(Time time) {
          getPk().setTime(time);
      }
  
      @Transient
      public Day getDay() {
          return getPk().getDay();
      }
  
      public void setDay(Day day) {
          getPk().setDay(day);
      }
  
  }
  </code></pre>
  
  <p>and the ID</p>
  
  <pre><code>@Embeddable
  public class UserAccessReservationId implements java.io.Serializable {
  
      private static final long serialVersionUID = 1L;
      private InternalParticipant internalParticipant;
      private Time time;
      private Day day;
  
      @ManyToOne
      public InternalParticipant getInternalParticipant() {
          return this.internalParticipant;
      }
  
      public void setInternalParticipant(InternalParticipant internalParticipant) {
          this.internalParticipant = internalParticipant;
      }
  
      @ManyToOne
      public Time getTime() {
          return this.time;
      }
  
      public void setTime(Time time) {
          this.time = time;
      }
  
      @ManyToOne
      public Day getDay() {
          return day;
      }
  
      public void setDay(Day day) {
          this.day = day;
      }
  }
  </code></pre>
  
  <p>butwhen I create an <code>UserAccessReservation</code> I receive this exception</p>
  
  <pre><code>Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'useraccess0_.internalParticipant_uhr_idReservation' in 'field list'
      at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
      at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
      at com.mysql.jdbc.Util.getInstance(Util.java:408)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
      at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2490)
      at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
      at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1966)
      at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
      at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:71)
      ... 178 more
  </code></pre>
  
  <p>Do you have idea about where is the error? Thanks
  <a href="https://i.stack.imgur.com/q2fir.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q2fir.png" alt="partial schema"></a></p>