title: OnetoOne Bi-directional Association Error on using referenceColumnName
body: <p><strong>Company Entity</strong></p>
  
  <pre><code>@Entity
  @Table(name="company")
  
  public class Company implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue
      private int id;
  
      @Column(name="company_id")
      private int cmpId;
  
      @Column(name="company_name")
      private String companyName;
  
      @OneToOne(fetch=FetchType.LAZY, mappedBy="company")
      private Employee employee;
  
  
  
  
  }
  </code></pre>
  
  <p><strong>Employee Entity</strong></p>
  
  <pre><code>@Entity
  @Table(name="employee")
  public class Employee implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue
      private int id;
  
      @Column(name="emp_id")
      private int empId;
  
      @Column(name="emp_name")
      private String empName;
  
      @OneToOne(fetch=FetchType.LAZY)
      @JoinColumn(name="cmp_id", referencedColumnName="company_id")
      private Company company;
  
  }
  </code></pre>
  
  <p><strong>Company Service</strong></p>
  
  <pre><code>@Service
  public class CompanyService {
  
      @Autowired
      private CompanyRepository companyRepo;
  
      public Company fetchCompany(int cmpId){
          System.out.println("11111111111111111");
          return companyRepo.findByCmpId(cmpId);
      }
  }
  </code></pre>
  
  <p><strong>Company Repo</strong></p>
  
  <pre><code>public interface CompanyRepository extends JpaRepository&lt;Company, Integer&gt;{ 
  
      @Query(value="select a from Company a join fetch a.employee where a.cmpId = ?1")
      public Company findByCmpId(int cmpId);
  }
  </code></pre>
  
  <p><strong>API</strong></p>
  
  <pre><code>@RequestMapping("/cmp/{cmpId}")
  public void findCmp(@PathVariable int cmpId){
      Company cmp = cmpService.fetchCompany(cmpId);
      System.out.println(cmp.getEmployee().getEmpName());
  }
  </code></pre>
  
  <p>Issue is when I am trying to execute my code, I am getting following error:</p>
  
  <pre><code>  Hibernate: select company0_.id as id1_1_0_, employee1_.id as id1_2_1_, company0_.company_id as company_2_1_0_, company0_.company_name as company_3_1_0_, employee1_.cmp_id as cmp_id4_2_1_, employee1_.emp_id as emp_id2_2_1_, employee1_.emp_name as emp_name3_2_1_ from company company0_ inner join employee employee1_ on company0_.id=employee1_.cmp_id where company0_.company_id=?
  2017-04-21 17:22:11.386 ERROR 10766 --- [nio-8105-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: Error accessing field [private int com.example.domain.Company.cmpId] by reflection for persistent property [com.example.domain.Company#cmpId] : 1; nested exception is org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private int com.example.domain.Company.cmpId] by reflection for persistent property [com.example.domain.Company#cmpId] : 1] with root cause
  
  java.lang.IllegalArgumentException: Can not set int field com.example.domain.Company.cmpId to java.lang.Integer
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) ~[na:1.8.0_91]
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) ~[na:1.8.0_91]
      at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58) ~[na:1.8.0_91]
      at sun.reflect.UnsafeIntegerFieldAccessorImpl.getInt(UnsafeIntegerFieldAccessorImpl.java:56) ~[na:1.8.0_91]
      at sun.reflect.UnsafeIntegerFieldAccessorImpl.get(UnsafeIntegerFieldAccessorImpl.java:36) ~[na:1.8.0_91]
      at java.lang.reflect.Field.get(Field.java:393) ~[na:1.8.0_91]
  </code></pre>
  
  <p>How to fix this? Also when I have removed <strong>referenceColumnName</strong>, then the error is removed but them it is joining with primary key of company class, which I dont want.?</p>