From df8c8d8eaa3fd74b2f6a76341611555ee6d8834d Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Sun, 22 Nov 2015 15:07:27 +0100 Subject: Add initial files --- src/jpa/Product.java | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/jpa/Product.java (limited to 'src/jpa/Product.java') 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 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 getCategoryCollection() { + return this.categoryCollection; + } + + public void setCategoryCollection(Set categoryCollection) { + this.categoryCollection = categoryCollection; + } + + public void addCategory(Category category) + { + Set categories = getCategoryCollection(); + if (!categories.contains(category)) + { + categories.add(category); + category.addProduct(this); + } + } +} -- cgit v1.2.3-70-g09d2