title: JoinColumn to an foreign key
body: <p>I'm trying to achieve this with hibernate:
  <a href="https://i.stack.imgur.com/rqh37.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rqh37.png" alt="table relationship"></a></p>
  
  <p>My codes is as follows:</p>
  
  <p>Device model</p>
  
  <pre><code>@Entity
  public class Device {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(nullable = false)
  private long id;
  
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "fk_user", nullable = true, referencedColumnName = "ID")
  private User user;
  ...
  }
  </code></pre>
  
  <p>Statistics model</p>
  
  <pre><code>@Entity
  public class Statistic {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(nullable = false)
  private long id;
  
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumns({ @JoinColumn(name = "fk_device", nullable = false, referencedColumnName = "ID"),
          @JoinColumn(name = "fk_device_user", nullable = false, referencedColumnName = "fk_user") })
  private Device device;
  ...
  }
  </code></pre>
  
  <p>However, there's an error saying there's no logical column fk_user in device.</p>
  
  <pre><code>Caused by: org.hibernate.MappingException: Unable to find column with logical name: fk_user in device
  </code></pre>
  
  <p>I suppose it is because fk_user is a foreign key. But how can I solve this? Thanks.</p>