title: How to join fields of two tables using Hibernate?
body: <p>I have two tables and related Java mapping.</p>
  
  <pre><code>CREATE TABLE country (
      code VARCHAR(3) PRIMARY KEY NOT NULL,
      name VARCHAR(100) NOT NULL
  );
  
  
  CREATE TABLE user (
      id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
      name VARCHAR(100) NOT NULL,
      country_code VARCHAR(3),
      FOREIGN KEY ( country_code ) REFERENCES country ( code )
  );
  </code></pre>
  
  <p>Here is my Java entities. Country POJO:</p>
  
  <pre><code>@Entity
  @Table(name = "country")
  public class Country {
  
      @Id
      @Column (name = "code")
      private String code;
  
      @Column (name = "name")
      private String name;
  </code></pre>
  
  <p>And User POJO:</p>
  
  <pre><code>@Entity
  @Table(name = "user")
  public class User implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;
  
      @Column(name = "name")
      private String name;
  
      @Column(name = "country_code")
      private String countryCode;
  </code></pre>
  
  <p>Question is how can I join <code>Contry.code</code> to <code>User.countryCode</code> in Hibernate using annotation? When I create User object with Hibernate I need to bind these two fields (code and countryCode) automatically.</p>