title: JPA mappedBy reference an unknown target entity
body: <p>I am writing a simple inventory database that contains tables for products, orders and customers. The database definition can be found here:</p>
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE public.customers
  (
      id integer NOT NULL DEFAULT nextval('customers_id_seq'::regclass),
      title character varying(10) COLLATE pg_catalog.&quot;default&quot; NOT NULL,
      first_name character varying(50) COLLATE pg_catalog.&quot;default&quot; NOT NULL,
      middle_names character varying(50) COLLATE pg_catalog.&quot;default&quot;,
      last_name character varying(50) COLLATE pg_catalog.&quot;default&quot; NOT NULL,
      email character varying(50) COLLATE pg_catalog.&quot;default&quot; NOT NULL,
      phone_number character varying(50) COLLATE pg_catalog.&quot;default&quot; NOT NULL,
      CONSTRAINT customers_pkey PRIMARY KEY (id)
  )
  
  CREATE TABLE public.products
  (
      id integer NOT NULL DEFAULT nextval('products_id_seq'::regclass),
      name character varying(100) COLLATE pg_catalog.&quot;default&quot; NOT NULL,
      sku integer NOT NULL,
      inventory_on_hand integer NOT NULL,
      reorder_threshold integer NOT NULL,
      price numeric(5,2),
      inventory_to_be_shipped integer NOT NULL,
      CONSTRAINT products_pkey PRIMARY KEY (id)
  )
  
  CREATE TABLE public.order_items
  (
      id integer NOT NULL DEFAULT nextval('order_items_id_seq'::regclass),
      product_id integer NOT NULL,
      order_id integer NOT NULL,
      CONSTRAINT order_items_pkey PRIMARY KEY (id),
      CONSTRAINT order_items_order_id_fkey FOREIGN KEY (order_id)
          REFERENCES public.orders (id) MATCH SIMPLE
          ON UPDATE NO ACTION
          ON DELETE NO ACTION,
      CONSTRAINT order_items_product_id_fkey FOREIGN KEY (product_id)
          REFERENCES public.products (id) MATCH SIMPLE
          ON UPDATE NO ACTION
          ON DELETE NO ACTION
  )
  
  CREATE TABLE public.orders
  (
      id integer NOT NULL DEFAULT nextval('orders_id_seq'::regclass),
      customer_id integer,
      order_date date NOT NULL DEFAULT now(),
      arrival_date date,
      CONSTRAINT orders_pkey PRIMARY KEY (id),
      CONSTRAINT orders_customer_id_fkey FOREIGN KEY (customer_id)
          REFERENCES public.customers (id) MATCH SIMPLE
          ON UPDATE NO ACTION
          ON DELETE NO ACTION
  )
  </code></pre>
  <p>I am trying to implement a Spring Security Resource server to perform CRUD operations on the database. I have implemented entity classes for each table in the database but when try to start the server I get a</p>
  <pre><code>org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: edu.finalyearproject.imsresourceserver.models.Order.customers in edu.finalyearproject.imsresourceserver.models.Customer.orders
  </code></pre>
  <p>My entity and repository classes can be found below:</p>
  <p>Product.java:</p>
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Table(name = &quot;products&quot;)
  @Data
  public class Product
  {
      @Id
      @GeneratedValue(strategy= GenerationType.IDENTITY)
      private Integer id;
      private String name;
      private Integer sku;
      private Float price;
      private Integer inventory_on_hand;
      private Integer reorder_threshold;
  
      @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY)
      @JoinTable(
              name = &quot;order_items&quot;,
              joinColumns = @JoinColumn(name = &quot;product_id&quot;),
              inverseJoinColumns = @JoinColumn(name = &quot;order_id&quot;)
      )
      private Set&lt;Order&gt; orders = new HashSet&lt;&gt;();
  }
  </code></pre>
  <p>Customer.java</p>
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Table(name = &quot;customers&quot;)
  @Data
  public class Customer
  {
      @Id
      @GeneratedValue(strategy= GenerationType.IDENTITY)
      private Integer id;
      private String title;
      private String first_name;
      private String middle_names;
      private String last_name;
      private String email;
      private String phone_number;
  
      @OneToMany(mappedBy = &quot;customer&quot;, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      private Set&lt;Order&gt; orders;
  }
  </code></pre>
  <p>Order.java</p>
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Table(name = &quot;orders&quot;)
  @Data
  public class Order
  {
      @Id
      @GeneratedValue(strategy= GenerationType.IDENTITY)
      private Integer id;
  
      @ManyToOne
      @JoinColumn(name=&quot;customer_id&quot;, nullable=false)
      private Customer customer;
  
      private Date order_date;
  
      private Date arrival_date;
  
      @ManyToMany(mappedBy = &quot;orders&quot;, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
      private Set&lt;Product&gt; products = new HashSet&lt;&gt;();
  }
  </code></pre>
  <p>I know the problem is related to the relationships between the entities, but I haven't been able to find a solution. Any help would be greatly appreciated.</p>