diff options
Diffstat (limited to 'src/jpa')
| -rw-r--r-- | src/jpa/Category.java | 125 | ||||
| -rw-r--r-- | src/jpa/Product.java | 94 | ||||
| -rw-r--r-- | src/jpa/User.java | 17 |
3 files changed, 97 insertions, 139 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 diff --git a/src/jpa/Product.java b/src/jpa/Product.java index dc0b3f8..baf29ca 100644 --- a/src/jpa/Product.java +++ b/src/jpa/Product.java @@ -1,51 +1,56 @@ package jpa; import java.io.Serializable; +import javax.persistence.*; import java.math.BigDecimal; -import java.util.Collection; import java.util.Set; -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; +/** + * The persistent class for the product database table. + * + */ @Entity +@Table(name="product") +@NamedQuery(name="Product.findAll", query="SELECT p FROM Product p") public class Product implements Serializable { + private static final long serialVersionUID = 1L; + @Id - @GeneratedValue(strategy=GenerationType.SEQUENCE) - private String id; + private int id; + @Lob private String description; - private BigDecimal price; + private BigDecimal height; private String name; - private BigDecimal width; + private BigDecimal price; - private BigDecimal height; + private BigDecimal width; + //bi-directional many-to-many association to Category @ManyToMany @JoinTable( - joinColumns=@JoinColumn(name="product_id"), - inverseJoinColumns=@JoinColumn(name="category_id")) - private Set<Category> categoryCollection; - - private static final long serialVersionUID = 1L; + name="product_category" + , joinColumns={ + @JoinColumn(name="product_id") + } + , inverseJoinColumns={ + @JoinColumn(name="category_id") + } + ) + private Set<Category> categories; public Product() { - super(); } - public String getId() { + public int getId() { return this.id; } - public void setId(String id) { + public void setId(int id) { this.id = id; } @@ -57,12 +62,12 @@ public class Product implements Serializable { this.description = description; } - public BigDecimal getPrice() { - return this.price; + public BigDecimal getHeight() { + return this.height; } - public void setPrice(BigDecimal price) { - this.price = price; + public void setHeight(BigDecimal height) { + this.height = height; } public String getName() { @@ -73,41 +78,28 @@ public class Product implements Serializable { this.name = name; } - public BigDecimal getWidth() { - return this.width; + public BigDecimal getPrice() { + return this.price; } - public void setWidth(BigDecimal width) { - this.width = width; + public void setPrice(BigDecimal price) { + this.price = price; } - public BigDecimal getHeight() { - return this.height; + public BigDecimal getWidth() { + return this.width; } - public void setHeight(BigDecimal height) { - this.height = height; + public void setWidth(BigDecimal width) { + this.width = width; } - public Collection getCategories() { - return this.getCategoryCollection(); - } - - public Set<Category> getCategoryCollection() { - return this.categoryCollection; + public Set<Category> getCategories() { + return this.categories; } - public void setCategoryCollection(Set<Category> categoryCollection) { - this.categoryCollection = categoryCollection; + public void setCategories(Set<Category> categories) { + this.categories = categories; } - public void addCategory(Category category) - { - Set<Category> categories = getCategoryCollection(); - if (!categories.contains(category)) - { - categories.add(category); - category.addProduct(this); - } - } -} +}
\ No newline at end of file diff --git a/src/jpa/User.java b/src/jpa/User.java index 32d2af8..d96d27e 100644 --- a/src/jpa/User.java +++ b/src/jpa/User.java @@ -1,20 +1,25 @@ package jpa; import java.io.Serializable; -import javax.persistence.Entity; -import javax.persistence.Id; +import javax.persistence.*; + +/** + * The persistent class for the user database table. + * + */ @Entity +@Table(name="user") +@NamedQuery(name="User.findAll", query="SELECT u FROM User u") public class User implements Serializable { + private static final long serialVersionUID = 1L; + @Id private String username; private String password; - private static final long serialVersionUID = 1L; - public User() { - super(); } public String getUsername() { @@ -33,4 +38,4 @@ public class User implements Serializable { this.password = password; } -} +}
\ No newline at end of file |
