title: Hibernate mapping exception with multiple @Id
body: <p>I have two entities with a relation between them.
  Here's my first entity:</p>
  
  <pre><code>    @Entity
      @Table(name = "APPLICATION_DEVICE")
      public class ApplicationDevice implements Serializable {
      [...]
      @Id
          @ManyToOne
          @JoinColumn(name = "udid", nullable=false)
          public Device getDevice()
          {
              return device;
          }
  
          public void setDevice(Device device)
          {
              this.device = device;
          }
  
          @Id
          public Long getApplicationId()
          {
              return applicationId;
          }
  
          public void setApplicationId(Long applicationId)
          {
              this.applicationId = applicationId;
          }
  [...]
  </code></pre>
  
  <p>Note it has a primery key with two fields: applicationId and a device (it is as another relation).</p>
  
  <p>And my other entity is:</p>
  
  <pre><code>@Entity
  @Table(name = "SEGMENT_APPLICATION_DEVICES")
  public class SegmentApplicationDevice
  {
  [...]
  
  @Id
      @GeneratedValue
      public Long getId()
      {
          return id;
      }
  
      public void setId(Long id)
      {
          this.id = id;
      }
  
      @ManyToOne
      public ApplicationDevice getApplicationDevice()
      {
          return applicationDevice;
      }
  
      public void setApplicationDevice(ApplicationDevice applicationDevice)
      {
          this.applicationDevice = applicationDevice;
      }
  
  [...]
  </code></pre>
  
  <p>And here's the exception of hibernate when it tries mapping this entities:</p>
  
  <pre><code>Exception constructing service 'HibernateSessionSource': Error invoking service builder method org.apache.tapestry5.hibernate.HibernateCoreModule.buildHibernateSessionSource(Logger, List, RegistryShutdownHub) (at HibernateCoreModule.java:123) (for service 'HibernateSessionSource'): Foreign key (FK5B8CB9821C11FEAE:SEGMENT_APPLICATION_DEVICES [applicationDevice_applicationId])) must have same number of columns as the referenced primary key (APPLICATION_DEVICE [udid,applicationId])
  </code></pre>
  
  <p>What i'm doint wrong? Thanks!</p>