title: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on entities.Ques#tion.examId references an unknown entity: long
body: <p>I'm trying to setup JPA with a hibernate implementation for the first time with this test project. Ran into the following error:</p>
  
  <pre><code>Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: ExamModulePu] Unable to build EntityManagerFactory
  at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924)
  at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
  at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:59)
  at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
  at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
  at service.tests.ExamServiceTest.main(ExamServiceTest.java:18)
  Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on entities.Question.examId references an unknown entity: long
  at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:109)
  at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1536)
  at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1457)
  at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1365)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1756)
  at org.hibernate.ejb.EntityManagerFactoryImpl.&lt;init&gt;(EntityManagerFactoryImpl.java:96)
  at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
  </code></pre>
  
  <p>These are my entities:</p>
  
  <pre><code>@Entity
  public class Exam implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private long id;
      private String name;
      private int numQuestions;
      private int minutesAllotted;
      private Date startDate;
      private Date endDate;
      @OneToMany(mappedBy = "examId", orphanRemoval = true)
      private List&lt;Question&gt; questionList;
          // Getters and setters here..
  }
  
  @Entity
  public class Question implements Serializable{
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private long id;
      @ManyToOne
      private long examId;
      private int points;
      private int timeLimit;
      private String text;
      private String category;
      @Embedded
      private List&lt;Answer&gt; answerList;
  }
  
  @Embeddable 
  public class Answer implements Serializable {
  
      private int optionNumber;
      private String text;
      private boolean correct;
  }
  </code></pre>
  
  <p>This is what my persistence.xml looks like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
      version="2.0"&gt;
      &lt;persistence-unit name="ExamModulePu"
          transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;class&gt;entities.Exam&lt;/class&gt;
          &lt;class&gt;entities.Question&lt;/class&gt;
          &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
          &lt;properties&gt;
              &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /&gt;
              &lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/exammoduledb" /&gt;
              &lt;property name="javax.persistence.jdbc.user" value="root" /&gt;
              &lt;property name="javax.persistence.jdbc.password" value="root" /&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="create" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>I haven't created any of the tables, but instead am depending on the <code>hibernate.hb2mddl.auto</code> to do so. But I believe my error springs up even before that happens as it can't generate the persistence unit. Any ideas what I'm doing wrong? I'm making sure I import only <code>javax.persistence.*;</code></p>