title: EclipseLink JPA uses a non-entity as target entity in the relationship attribute
body: <p>I'm getting the following error when I'm running my test in JUnit (version 4.12) to make a order:</p>
  
  <pre><code>Local Exception Stack: 
  Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
  Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@2c7b84de
  Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException
  Exception Description: Predeployment of PersistenceUnit [snel-transport-test] failed.
  Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
  Exception Description: [class nl.cimsolutions.snel_transport.models.OrderLine] uses a non-entity [class nl.cimsolutions.snel_transport.models.Product] as target entity in the relationship attribute [field product].
      at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
      at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:107)
      at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
      at nl.cimsolutions.snel_transport.services.AbstractFacade.getEntityManagerFactory(AbstractFacade.java:31)
      at nl.cimsolutions.snel_transport.services.AbstractFacade.find(AbstractFacade.java:77)
      at controller.OrdersControllerTest.testAddOrder(OrdersControllerTest.java:345)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
  Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException
  Exception Description: Predeployment of PersistenceUnit [snel-transport-test] failed.
  </code></pre>
  
  <p>However when I run the webapp it does work when I make a order.</p>
  
  <p>Below you can see the code:</p>
  
  <p>OrderLine.java:</p>
  
  <pre><code>@Entity 
  public class OrderLine implements Serializable {
  
      private static final long serialVersionUID = 1L;
      @TableGenerator(
              name = "OrderLineGenerator",
              allocationSize = 1,
              initialValue = 1)
      @Id
      @GeneratedValue(strategy = GenerationType.TABLE,
          generator="OrderLineGenerator")
      private Long id;
      @Column(name = "orderId")
      private Long orderId;
      @ManyToOne(targetEntity = nl.cimsolutions.snel_transport.models.Product.class)
      @JoinColumn(name="productId")
      private Product product;
      private int amount;
  
      //More code..
  }
  </code></pre>
  
  <p>Product.java:</p>
  
  <pre><code>@Entity
  public class Product {
  
      @TableGenerator(
              name = "ProductGenerator",
              allocationSize = 1,
              initialValue = 1)
      @Id
      @GeneratedValue(strategy = GenerationType.TABLE,
              generator="ProductGenerator")
      private Long id;
      @Column(name="Name")
      private String Name;
      @Column(name="Price")
      private Double Price;
      @Column(name="code")
      private String Code;
      @OneToOne
      @JoinColumn(name="categoryId")
      private Category Categories;
  
      @OneToMany(mappedBy = "product", targetEntity = nl.cimsolutions.snel_transport.models.OrderLine.class)
      private List&lt;OrderLine&gt; orderLines;
  
      public Product(){
  
      }
  
      public Product(Long Id, String name,String code, Double price, Category categories) {
          super();
          id = Id;
          Name = name;
          Price = price;
          Code = code;
          Categories = categories;
      }
  
      //More code..
  }
  </code></pre>
  
  <p>persistence.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.1"
      xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"&gt;
      &lt;persistence-unit name="snel-transport" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.Orders&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.OrderLine&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.OrderList&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.Customer&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.Product&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.Category&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.Status&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.Truck&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.Route&lt;/class&gt;
          &lt;!-- &lt;jta-data-source&gt;java:app/snel-transport&lt;/jta-data-source&gt; --&gt;
          &lt;!-- &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt; --&gt;
          &lt;properties&gt;
              &lt;property
                  name="javax.persistence.schema-generation.database.action"
                  value="create" /&gt;
              &lt;property name="eclipselink.cache.shared.default" value="false"/&gt;
              &lt;property name="eclipselink.canonicalmodel.subpackage"
                  value="dev" /&gt;
              &lt;property name="javax.persistence.sql-load-script-source"
                  value="META-INF/sql/insert.sql" /&gt;
              &lt;property name="javax.persistence.schema-generation-target"
                  value="database" /&gt;
              &lt;property name="javax.persistence.jdbc.driver"
                  value="org.postgresql.Driver" /&gt;
              &lt;property name="javax.persistence.jdbc.url"
                  value="jdbc:postgresql://localhost:5432/snel-transport" /&gt;
              &lt;property name="javax.persistence.jdbc.user" value="transport_user" /&gt;
              &lt;property name="javax.persistence.jdbc.password"
                  value="admin" /&gt;
  
              &lt;property name="javax.persistence.jdbc.show_sql" value="true" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
      &lt;persistence-unit name="snel-transport-test" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.Orders&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.OrderLine&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.OrderList&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.Customer&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.Product&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.Category&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.Status&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.Truck&lt;/class&gt;
          &lt;class&gt;nl.cimsolutions.snel_transport.models.Route&lt;/class&gt;
          &lt;properties&gt;
              &lt;property
                  name="javax.persistence.schema-generation.database.action"
                  value="drop-and-create" /&gt;
              &lt;property name="eclipselink.canonicalmodel.subpackage"
                  value="test" /&gt;
  
              &lt;property name="javax.persistence.sql-load-script-source"
                  value="META-INF/sql/insert.sql" /&gt;
              &lt;property name="javax.persistence.schema-generation-target"
                  value="database" /&gt;
              &lt;property name="javax.persistence.jdbc.driver"
                  value="org.postgresql.Driver" /&gt;
              &lt;property name="javax.persistence.jdbc.url"
                  value="jdbc:postgresql://localhost:5432/snel-transport-test" /&gt;
              &lt;property name="javax.persistence.jdbc.user" value="transport_user" /&gt;
              &lt;property name="javax.persistence.jdbc.password"
                  value="admin" /&gt;
              &lt;property name="driverClass" value="org.postgresql.Driver" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>As you can see I have already clearly marked <code>Product</code> and <code>OrderLine</code> as entities through using the <code>@Entity</code> annotation in 
  <code>Product.java</code> and in <code>OrderLine.java</code>. I have also listed both classes in the <code>persistence.xml</code> file.</p>
  
  <p>I can remove <code>mappedBy</code> in <code>Product.java</code> which fixes the problem, but I don't want this because I don't want to create an extra table.</p>
  
  <p>I have already checked these solutions:</p>
  
  <p><a href="https://stackoverflow.com/questions/8353752/jpa-error-uses-a-non-entity-class-ch-printsoft-mailhouse-usermgr-entity-departm">jpa error uses a non-entity [class ch.printsoft.mailhouse.usermgr.entity.Department] as target entity in the relationship attribute</a></p>
  
  <p><a href="https://stackoverflow.com/questions/29408259/jpa-eclipselink-uses-a-non-entity-as-target-entity-in-the-relationship-attribute">JPA EclipseLink uses a non-entity as target entity in the relationship attribute</a></p>
  
  <p><a href="https://stackoverflow.com/questions/27422993/eclipselink-non-entity-as-target-entity-in-the-relationship-attribute">EclipseLink - non Entity as target entity in the relationship attribute</a></p>
  
  <p>But I couldn't find something that would solve my problem. Anyone that has a clue how I can fix this?</p>