title: OneToOne with Composite Key
body: <p>Trying to create a one to one on a table with a composite key.
  I'm unable to get it to work and getting this error:</p>
  
  <p>Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext-dao.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: broken column mapping for: compensation.id of: com.ciwise.model.Focus</p>
  
  <p><strong>Compensation.java:</strong></p>
  
  <pre><code>package com.ciwise.model;
  
  import java.io.Serializable;
  
  import javax.persistence.Column;
  import javax.persistence.EmbeddedId;
  import javax.persistence.Entity;
  import javax.persistence.Table;
  
  @Entity
  @Table(name = "commissions")
  public class Compensation  implements Serializable {
  
  private static final long serialVersionUID = 1L;
  
  /**
   * Composite key
   */
  private CompensationPK compensationPK;
  
  /**
   * This year monthly net sales
   */
  private double tYMonthlyNetSales;
  
  /**
   * Last year monthly net sales
   */
  
  private double lYMonthlyNetSales;
  
  /**
   * This year YTD net sales
   */
  private double tYYTDNetSales;
  
  private Focus focus;
  
  /**
   * Getters and Setters
   */
  
  @OneToOne( mappedBy = "compensation", fetch = FetchType.EAGER)
  @JoinColumn(name = "FOCUS_ID")
  public Focus getFocus() {
      return focus;
  }
  
  public void setFocus(Focus focus) {
      this.focus = focus;
  }
  
  @EmbeddedId
  public CompensationPK getCompensationPK() {
      return compensationPK;
  }
  
  public void setCompensationPK(CompensationPK compensationPK) {
      this.compensationPK = compensationPK;
  }
  
  @Column(name = "TY_MONTHLY_NET_SALES")
  public double gettYMonthlyNetSales() {
      return tYMonthlyNetSales;
  }
  
  public void settYMonthlyNetSales(double tYMonthlyNetSales) {
      this.tYMonthlyNetSales = tYMonthlyNetSales;
  }
  
  @Column(name = "LY_MONTHLY_NET_SALES")
  public double getlYMonthlyNetSales() {
      return lYMonthlyNetSales;
  }
  
  public void setlYMonthlyNetSales(double lYMonthlyNetSales) {
      this.lYMonthlyNetSales = lYMonthlyNetSales;
  }
  
  @Column(name = "TY_YTD_NET_SALES")
  public double gettYYTDNetSales() {
      return tYYTDNetSales;
  }
  
  public void settYYTDNetSales(double tYYTDNetSales) {
      this.tYYTDNetSales = tYYTDNetSales;
  }
  }
  </code></pre>
  
  <p><strong>CompensationPK.java</strong></p>
  
  <pre><code>package com.ciwise.model;
  import java.io.Serializable;
  import javax.persistence.Column;
  import javax.persistence.Embeddable;
  
  @Embeddable
  public class CompensationPK implements Serializable {
  
  private String divisionId;
  
  private String repId;
  
  private int focusId;
  
  private int repTypeId;
  
  private int commissionYear;
  
  private int commissionMonth;
  
  @Column(name = "DIVISION_ID")
  public String getDivisionId() {
      return divisionId;
  }
  
  @Column(name = "REP_ID")
  public String getRepId() {
      return repId;
  }
  
  @Column(name = "FOCUS_ID")
  public int getFocusId() {
      return focusId;
  }
  
  @Column(name = "REPTYPE_ID")
  public int getRepTypeId() {
      return repTypeId;
  }
  
  @Column(name = "COMMISSION_YEAR")
  public int getCommissionYear() {
      return commissionYear;
  }
  
  @Column(name = "COMMISSION_MONTH")
  public int getCommissionMonth() {
      return commissionMonth;
  }
  
  
  
  public void setDivisionId(String divisionId) {
      this.divisionId = divisionId;
  }
  
  public void setRepId(String repId) {
      this.repId = repId;
  }
  
  public void setFocusId(int focusId) {
      this.focusId = focusId;
  }
  
  public void setRepTypeId(int repTypeId) {
      this.repTypeId = repTypeId;
  }
  
  public void setCommissionYear(int commissionYear) {
      this.commissionYear = commissionYear;
  }
  
  public void setCommissionMonth(int commissionMonth) {
      this.commissionMonth = commissionMonth;
  }
  
  @Override
  public boolean equals(Object o) {
      return false;
  }
  
  @Override
  public int hashCode() {
      return 0;
  }
  }
  </code></pre>
  
  <p><strong>Focus.java:</strong></p>
  
  <p>package com.ciwise.model;</p>
  
  <pre><code>import java.io.Serializable;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name = "CT_FOCUS")
  public class Focus implements Serializable {
  
  private int focusId;
  private String focusDesc;
  private String focusYN;
  private Compensation compensation;
  
  @OneToOne
  @PrimaryKeyJoinColumn
  public Compensation getCompensation() {
      return compensation;
  }
  
  public void setCompensation(Compensation compensation) {
      this.compensation = compensation;
  }
  
  public Focus() {
  };
  
  @Id
  @Column(name = "FOCUS_ID")
  public int getFocusId() {
      return focusId;
  }
  
  public void setFocusId(int focusId) {
      this.focusId = focusId;
  }
  
  @Column(name = "FOCUS_DESC", length = 16)
  public String getFocusDesc() {
      return focusDesc;
  }
  
  public void setFocusDesc(String focusDesc) {
      this.focusDesc = focusDesc;
  }
  
  @Column(name = "FOCUS_YN", length = 1)
  public String getFocusYN() {
      return focusYN;
  }
  
  public void setFocusYN(String focusYN) {
      this.focusYN = focusYN;
  }
  }
  </code></pre>