diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-11-22 15:07:27 +0100 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-11-23 15:57:23 +0100 |
| commit | df8c8d8eaa3fd74b2f6a76341611555ee6d8834d (patch) | |
| tree | 40e93e3b3674f32d4870486eb9f5870d9fe45b2b /src/jpa/Product.java | |
| download | JCatalog-df8c8d8eaa3fd74b2f6a76341611555ee6d8834d.tar.gz JCatalog-df8c8d8eaa3fd74b2f6a76341611555ee6d8834d.zip | |
Add initial files
Diffstat (limited to 'src/jpa/Product.java')
| -rw-r--r-- | src/jpa/Product.java | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/jpa/Product.java b/src/jpa/Product.java new file mode 100644 index 0000000..dc0b3f8 --- /dev/null +++ b/src/jpa/Product.java @@ -0,0 +1,113 @@ +package jpa; + +import java.io.Serializable; +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; + +@Entity +public class Product implements Serializable { + @Id + @GeneratedValue(strategy=GenerationType.SEQUENCE) + private String id; + + private String description; + + private BigDecimal price; + + private String name; + + private BigDecimal width; + + private BigDecimal height; + + @ManyToMany + @JoinTable( + joinColumns=@JoinColumn(name="product_id"), + inverseJoinColumns=@JoinColumn(name="category_id")) + private Set<Category> categoryCollection; + + private static final long serialVersionUID = 1L; + + public Product() { + super(); + } + + public String getId() { + return this.id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + + public BigDecimal getPrice() { + return this.price; + } + + public void setPrice(BigDecimal price) { + this.price = price; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public BigDecimal getWidth() { + return this.width; + } + + public void setWidth(BigDecimal width) { + this.width = width; + } + + public BigDecimal getHeight() { + return this.height; + } + + public void setHeight(BigDecimal height) { + this.height = height; + } + + public Collection getCategories() { + return this.getCategoryCollection(); + } + + public Set<Category> getCategoryCollection() { + return this.categoryCollection; + } + + public void setCategoryCollection(Set<Category> categoryCollection) { + this.categoryCollection = categoryCollection; + } + + public void addCategory(Category category) + { + Set<Category> categories = getCategoryCollection(); + if (!categories.contains(category)) + { + categories.add(category); + category.addProduct(this); + } + } +} |
