summaryrefslogtreecommitdiffstats
path: root/src/jpa/Category.java
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2015-11-22 17:02:23 +0100
committerStefan Suhren <suhren.stefan@fh-swf.de>2015-11-23 15:57:23 +0100
commit25ae0a23d15383df7f84ad51ee8f078c519ed963 (patch)
treefb5978df15648f4af58631939c58b5e1a5c6b0d4 /src/jpa/Category.java
parentdf8c8d8eaa3fd74b2f6a76341611555ee6d8834d (diff)
downloadJCatalog-25ae0a23d15383df7f84ad51ee8f078c519ed963.tar.gz
JCatalog-25ae0a23d15383df7f84ad51ee8f078c519ed963.zip
Get it to run on newest versions
Diffstat (limited to 'src/jpa/Category.java')
-rw-r--r--src/jpa/Category.java125
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