title: Hibernate join using non-primary key column
body: <p>I have two tables:</p>
  
  <blockquote>
    <ol>
    <li><p>users:</p>
    
    <ul>
    <li>user_id (primary)</li>
    <li>ip (unique)</li>
    <li>etc ..</li>
    </ul></li>
    <li><p>services_to_ip</p>
    
    <ul>
    <li>id (primary)</li>
    <li>service_id</li>
    <li>ip</li>
    <li>etc ..</li>
    </ul></li>
    </ol>
  </blockquote>
  
  <p>In class User:</p>
  
  <pre><code>@OneToMany()
  @JoinColumn(name = "ip", insertable = false, nullable = false, updatable = false)
  public List&lt;QPlanService&gt; getPlanServices() {
      return planServices;
  }
  </code></pre>
  
  <p>Using MySQL query log we get something like that:</p>
  
  <pre><code>SELECT *
  FROM services_users planservic0_ 
       LEFT OUTER JOIN services qservice1_ 
            ON planservic0_.service_id = qservice1_.id 
  WHERE planservic0_.ip = 777
  </code></pre>
  
  <p>In WHERE condition the 'user_id' field used (the default field is primary key - users.id) (user_id=777).</p>
  
  <p>How can I specify that I need to take the value of the 'ip' field from User entity, not 'user_id'?</p>
  
  <p>I will be grateful for any help!</p>