diff options
Diffstat (limited to 'src/jpa/Category.java')
| -rw-r--r-- | src/jpa/Category.java | 125 |
1 files changed, 43 insertions, 82 deletions
diff --git a/src/jpa/Category.java b/src/jpa/Category.java index c29c1f7..195b6e8 100644 --- a/src/jpa/Category.java +++ b/src/jpa/Category.java @@ -1,103 +1,64 @@ package jpa; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; +import javax.persistence.*; import java.util.Set; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.ManyToMany; +/** + * The persistent class for the category database table. + * + */ @Entity -public class Category implements Serializable -{ - @Id - private int id; +@Table(name="category") +@NamedQuery(name="Category.findAll", query="SELECT c FROM Category c") +public class Category implements Serializable { + private static final long serialVersionUID = 1L; - private String name; + @Id + private int id; - private String description; + private String description; - @ManyToMany(mappedBy = "categoryCollection") - private Set<Product> productCollection; + private String name; - private static final long serialVersionUID = 1L; + //bi-directional many-to-many association to Product + @ManyToMany(mappedBy="categories") + private Set<Product> products; - public Category() - { - super(); - } + public Category() { + } - public int getId() - { - return this.id; - } + public int getId() { + return this.id; + } - public void setId(int id) - { - this.id = id; - } + public void setId(int id) { + this.id = id; + } - public String getName() - { - return this.name; - } + public String getDescription() { + return this.description; + } - public void setName(String name) - { - this.name = name; - } + public void setDescription(String description) { + this.description = description; + } - public String getDescription() - { - return this.description; - } + public String getName() { + return this.name; + } - public void setDescription(String description) - { - this.description = description; - } + public void setName(String name) { + this.name = name; + } - /** - * The method <code>getProductCollection()</code> returns a - * Collection object that is incompatible with JSF. - * - * @return collection of product objects. - */ - public Collection<Product> getProducts() - { - Collection<Product> c = new ArrayList<Product>(); - - for (Iterator iter = getProductCollection().iterator(); iter.hasNext();) - { - Product product = (Product) iter.next(); - c.add(product); -// System.out.println(product.getName()); - } - - return c; - } + public Set<Product> getProducts() { + return this.products; + } - public Set<Product> getProductCollection() - { - return this.productCollection; - } + public void setProducts(Set<Product> products) { + this.products = products; + } - public void setProductCollection(Set<Product> productCollection) - { - this.productCollection = productCollection; - } - - public void addProduct(Product product) - { - Set<Product> products = getProductCollection(); - if (!products.contains(product)) - { - products.add(product); - product.addCategory(this); - } - } - -} +}
\ No newline at end of file |
