title: Use of @OneToMany or @ManyToMany targeting an unmapped class (Category,SubCategory,Product)
body: <p>I devised Category,SubCategory and Product entities for JSF project and I had an issue about mapping between SubCategory and Product with ManytoMany relation. Here are Category,SubCategory and Products below. How can I solve out this mapping excepiton. Thks.</p>
  
  <pre><code>    @Entity
      @Table(name="CATEGORY",schema="DEMO")
      public class Category implements Serializable{
  
      @Id
      @SequenceGenerator(name="catseq",sequenceName="seqCatSEQ",allocationSize=1)
      @GeneratedValue(generator="catseq",strategy=GenerationType.SEQUENCE)
      @Column(name="ID")
      private Integer id;
  
      @Column(name="NAME")
      private String name;
  
      @Column(name="CAT_DESC")
      private String catDesc;
  
  
      @OneToMany(cascade = { CascadeType.PERSIST },mappedBy="category")
      private Set&lt;SubCategory&gt; subcategories = new HashSet();
  
      public Category() {
          super();
          // TODO Auto-generated constructor stub
      }
  
  
      public Category(String name, String catDesc) {
          super();
          this.name = name;
          this.catDesc = catDesc;
      }
  
  
      public Integer getId() {
          return id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getCatDesc() {
          return catDesc;
      }
  
      public void setCatDesc(String catDesc) {
          this.catDesc = catDesc;
      }
  
  
      public Set&lt;SubCategory&gt; getSubcategories() {
          return subcategories;
      }
  
  
      public void setSubcategories(Set&lt;SubCategory&gt; subcategories) {
          this.subcategories = subcategories;
      }
  
  
  }
  </code></pre>
  
  <p>SubCategory:</p>
  
  <pre><code>package entities;
  
  import java.io.Serializable;
  import java.util.HashSet;
  import java.util.Set;
  
  import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.ManyToMany;
  import javax.persistence.ManyToOne;
  import javax.persistence.OneToMany;
  import javax.persistence.SequenceGenerator;
  import javax.persistence.Table;
  
  
  @Entity
  @Table(name="SUBCATEGORY",schema="DEMO")
  public class SubCategory implements Serializable{
  
      @Id
      @SequenceGenerator(name="subcatseq",sequenceName="seqSubCatSEQ",allocationSize=1)
      @GeneratedValue(generator="subcatseq",strategy=GenerationType.SEQUENCE)
      @Column(name="ID")
      private Integer id;
  
      @Column(name="SUBNAME")
      private String SubName;
  
      @Column(name="SUBNAME_DESC")
      private String SubNameDes;
  
      @ManyToOne(cascade={CascadeType.PERSIST,CascadeType.REMOVE})
      @JoinColumn(name = "CAT_ID")
      private Category category;
  
      @ManyToMany(cascade=CascadeType.PERSIST,mappedBy="subcategories")
      Set&lt;Product&gt; products = new HashSet&lt;Product&gt;();
  
  
      public SubCategory() {
          super();
          // TODO Auto-generated constructor stub
      }
  
      public SubCategory(String subName, String subNameDes) {
          super();
          SubName = subName;
          SubNameDes = subNameDes;
      }
  
      public Integer getId() {
          return id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }
  
      public String getSubName() {
          return SubName;
      }
  
      public void setSubName(String subName) {
          SubName = subName;
      }
  
      public String getSubNameDes() {
          return SubNameDes;
      }
  
      public void setSubNameDes(String subNameDes) {
          SubNameDes = subNameDes;
      }
  
  
      public Category getCategory() {
          return category;
      }
  
      public void setCategory(Category category) {
          this.category = category;
      }
  
  
  
  }
  </code></pre>
  
  <p>Product:</p>
  
  <pre><code>import java.io.Serializable;
  import java.util.HashSet;
  import java.util.Set;
  
  import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.JoinTable;
  import javax.persistence.ManyToMany;
  import javax.persistence.SequenceGenerator;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="PRODUCTS",schema="DEMO")
  public class Product implements Serializable{
  
      @Id
      @SequenceGenerator(name="proseq",sequenceName="proSEQ",allocationSize=1)
      @GeneratedValue(generator="proseq",strategy=GenerationType.SEQUENCE)
      @Column(name="ID")
      private Integer id;
  
  
      @Column(name="NAME")
      private String productName;
  
      @Column(name="QUANTITY")
      private Integer quantity;
  
      @Column(name="PRICE")
      private Double price;
  
      @Column(name="PRODUCT_DESC")
      private String productDes;
  
  
      @ManyToMany(cascade=CascadeType.ALL)
      @JoinTable(name="PRODUCT_SUBCATEGORY", 
        joinColumns={@JoinColumn(name="PRODUCT_ID")},
        inverseJoinColumns={@JoinColumn(name="SUBCATEGORY_ID")}
      ) 
      Set&lt;SubCategory&gt; subcategories = new HashSet&lt;SubCategory&gt;();
  
  
      public Product() {
          super();
          // TODO Auto-generated constructor stub
      }
  
  
      public Product(String productName, Integer quantity, Double price, String productDes,
              Set&lt;SubCategory&gt; subcategories) {
          super();
          this.productName = productName;
          this.quantity = quantity;
          this.price = price;
          this.productDes = productDes;
          this.subcategories = subcategories;
      }
  
  
      public Integer getId() {
          return id;
      }
  
  
      public void setId(Integer id) {
          this.id = id;
      }
  
  
      public String getProductName() {
          return productName;
      }
  
  
      public void setProductName(String productName) {
          this.productName = productName;
      }
  
  
      public Integer getQuantity() {
          return quantity;
      }
  
  
      public void setQuantity(Integer quantity) {
          this.quantity = quantity;
      }
  
  
      public Double getPrice() {
          return price;
      }
  
  
      public void setPrice(Double price) {
          this.price = price;
      }
  
  
      public String getProductDes() {
          return productDes;
      }
  
  
      public void setProductDes(String productDes) {
          this.productDes = productDes;
      }
  
  
      public Set&lt;SubCategory&gt; getSubcategories() {
          return subcategories;
      }
  
  
      public void setSubcategories(Set&lt;SubCategory&gt; subcategories) {
          this.subcategories = subcategories;
      }
  
  
  }
  </code></pre>