title: @OneToOne mapping JPA: unknown column in field list
body: <p>I have a database as follows</p>
  <pre><code>Table Enterprise
  ent_id (PK)
  loc_id
  ent_name
  
  Table Location
  loc_id (PK)
  loc_name
  </code></pre>
  <p>So I want to add a field into the Enterprise model class: &quot;Location&quot; which is a @OneToOne relationship. Unfortunately, when adding this field, the application doesn't work anymore.</p>
  <p>The code in the Enterprise class for Location:</p>
  <pre><code>@OneToOne
  @JoinColumn(name=&quot;loc_id&quot;,referencedColumnName=&quot;loc_id&quot;)
  private Location location;
  </code></pre>
  <p>With a getter &amp; setter for location.</p>
  <p>I get the following error when adding this Location field:</p>
  <blockquote>
  <p>PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet</p>
  <p>[...]</p>
  <p>Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'enterprise0_.location' in 'field list'</p>
  </blockquote>
  <p>It seems to me that it is searching for a column 'location' in the database, but this column isn't in the database. It should use the loc_id column instead! I tried adding @Transient, but that doesn't work.</p>
  <p>Thanks for any help!</p>
  <blockquote>
  <p>Enterprise Class</p>
  </blockquote>
  <pre><code>@Entity
  @Table(name = &quot;Enterprise&quot;)
  public class Enterprise implements Serializable {
  private int entId;
  private int locId;
  private String entName;
  private int entDescription;
  
  @OneToMany(mappedBy = &quot;enterprise&quot;)
  private List&lt;SalesOrder&gt; salesOrders;
  
  @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = &quot;ent_id&quot;)
  public int getEntId() {
      return entId;
  }
  
  public void setEntId(int entId) {
      this.entId = entId;
  }
  
  @Basic
  @Column(name = &quot;loc_id&quot;)
  public int getLocId() {
      return locId;
  }
  
  public void setLocId(int locId) {
      this.locId = locId;
  }
  
  @Basic
  @Column(name = &quot;ent_name&quot;)
  public String getEntName() {
      return entName;
  }
  
  public void setEntName(String entName) {
      this.entName = entName;
  }
  
  @Basic
  @Column(name = &quot;ent_description&quot;)
  public int getEntDescription() {
      return entDescription;
  }
  
  public void setEntDescription(int entDescription) {
      this.entDescription = entDescription;
  }
  
  //bi-directional one-to-one association to Location
  @OneToOne(cascade = CascadeType.ALL)
  @JoinColumn(name=&quot;loc_id&quot;,referencedColumnName=&quot;loc_id&quot;)
  private Location location;
  
  
  public Location getLocation() {
      return this.location;
  }
  
  public void setLocation(Location location) {
      this.location = location;
  }
  </code></pre>
  <blockquote>
  <p>Location class</p>
  </blockquote>
  <pre><code>private int locId;
  private String locCountry;
  private int locPostcode;
  private String locCity;
  private String locStreet;
  private int locNumber;
  private Integer locSubNumber;
  
  
  @Override
  public String toString() {
      return locStreet + &quot; &quot; + locNumber + &quot;, &quot; + locPostcode  + &quot; &quot; + locCity + &quot;, &quot; + locCountry;
  }
  
  @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = &quot;loc_id&quot;)
  public int getLocId() {
      return locId;
  }
  
  public void setLocId(int locId) {
      this.locId = locId;
  }
  
  @Basic
  @Column(name = &quot;loc_country&quot;)
  public String getLocCountry() {
      return locCountry;
  }
  
  public void setLocCountry(String locCountry) {
      this.locCountry = locCountry;
  }
  
  @Basic
  @Column(name = &quot;loc_postcode&quot;)
  public int getLocPostcode() {
      return locPostcode;
  }
  
  public void setLocPostcode(int locPostcode) {
      this.locPostcode = locPostcode;
  }
  
  @Basic
  @Column(name = &quot;loc_city&quot;)
  public String getLocCity() {
      return locCity;
  }
  
  public void setLocCity(String locCity) {
      this.locCity = locCity;
  }
  
  @Basic
  @Column(name = &quot;loc_street&quot;)
  public String getLocStreet() {
      return locStreet;
  }
  
  public void setLocStreet(String locStreet) {
      this.locStreet = locStreet;
  }
  
  @Basic
  @Column(name = &quot;loc_number&quot;)
  public int getLocNumber() {
      return locNumber;
  }
  
  public void setLocNumber(int locNumber) {
      this.locNumber = locNumber;
  }
  
  @Basic
  @Column(name = &quot;loc_sub_number&quot;)
  public Integer getLocSubNumber() {
      return locSubNumber;
  }
  
  public void setLocSubNumber(Integer locSubNumber) {
      this.locSubNumber = locSubNumber;
  }
  </code></pre>