title: Why doesn't this setup work for a foreign key relationship in JPA and Hibernate?
body: <p>I'm trying to set up a foreign key relationship with <a href="http://en.wikipedia.org/wiki/Java_Persistence_API" rel="nofollow">JPA</a> annotations and generate the tables using <a href="http://en.wikipedia.org/wiki/Hibernate_%28Java%29" rel="nofollow">Hibernate</a>, but I get an error and can't see the reason for it. I execute the main method in User to generate the tables.</p>
  
  <p>Here's the error -</p>
  
  <pre><code>INFO: Hibernate Validator not found: ignoring
  Exception in thread "main" org.hibernate.MappingException: Could not determine type    for: com.site.model.Name, at table: USER, for columns: [org.hibernate.mapping.Column(name)]
  at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:306)
  at org.hibernate.mapping.Column.getSqlTypeCode(Column.java:164)
  at org.hibernate.mapping.Column.getSqlType(Column.java:208)
  at org.hibernate.mapping.Table.sqlCreateString(Table.java:418)
  at org.hibernate.cfg.Configuration.generateSchemaCreationScript(Configuration.java:1099)
  at org.hibernate.tool.hbm2ddl.SchemaExport.&lt;init&gt;(SchemaExport.java:131)
  at org.hibernate.tool.hbm2ddl.SchemaExport.&lt;init&gt;(SchemaExport.java:92)
  at com.thepoliticalbottomline.model.User.main(User.java:55)
  </code></pre>
  
  <p>And the source code,</p>
  
  <pre><code>package com.sitename.model;
  
  import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.OneToOne;
  import javax.persistence.PrimaryKeyJoinColumn;
  import javax.persistence.Table;
  
  import org.hibernate.cfg.Configuration;
  import org.hibernate.tool.hbm2ddl.SchemaExport;
  
  @Entity
  public class User {
      private Long id;
      private String password;
      private Name name;
  
      @Id
      @GeneratedValue
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      public void setName(Name name) {
          this.name = name;
      }
      @OneToOne(cascade = CascadeType.ALL)
      @PrimaryKeyJoinColumn
      public Name getName() {
          return name;
      }
  
      public static void main(String args[]) {
          Configuration config = new Configuration();
          config.addAnnotatedClass(User.class);
          config.addAnnotatedClass(Name.class);
          config.configure();
          new SchemaExport(config).create(true, true);
      }
  }
  </code></pre>
  
  <p>Class Name,</p>
  
  <pre><code>package com.sitename.model;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  
  @Entity
  public class Name {
      private Long id;
      private String first;
      private String middle;
      private String last;
  
      /**
       * @return the id
       */
      @Id
      @GeneratedValue
      public Long getId() {
          return id;
      }
  
      /**
      * @param id the id to set
      */
      public void setId(Long id) {
          this.id = id;
      }
  
      /**
       * @return the first
       */
      public String getFirst() {
          return first;
      }
  
      /**
       * @param first the first to set
       */
      public void setFirst(String first) {
          this.first = first;
      }
  
      /**
       * @return the middle
       */
      public String getMiddle() {
          return middle;
      }
  
      /**
       * @param middle the middle to set
       */
      public void setMiddle(String middle) {
          this.middle = middle;
      }
  
      /**
       * @return the last
       */
      public String getLast() {
          return last;
      }
  
      /**
       * @param last the last to set
       */
      public void setLast(String last) {
          this.last = last;
      }
  }
  </code></pre>