Commit 0cf0778d by tkfftk

many to many relation

git-svn-id: https://dev.intra.insomnia.fi/svn/trunk@38 8cf89bec-f6a3-4178-919f-364fb3449fe5
1 parent b2a982ed
...@@ -12,6 +12,7 @@ import javax.persistence.CascadeType; ...@@ -12,6 +12,7 @@ import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
...@@ -39,8 +40,9 @@ public class FoodWaveTemplate implements Serializable { ...@@ -39,8 +40,9 @@ public class FoodWaveTemplate implements Serializable {
private String templateName; private String templateName;
@Column(name = "template_description", length = 2147483647) @Column(name = "template_description", length = 2147483647)
private String templateDescription; private String templateDescription;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "foodWaveTemplatesId")
private List<FoodWaveTemplateProduct> foodWaveTemplateProductList; @ManyToMany(mappedBy = "foodWaveTemplate")
private List<Product> products;
public FoodWaveTemplate() { public FoodWaveTemplate() {
} }
...@@ -78,14 +80,6 @@ public class FoodWaveTemplate implements Serializable { ...@@ -78,14 +80,6 @@ public class FoodWaveTemplate implements Serializable {
this.templateDescription = templateDescription; this.templateDescription = templateDescription;
} }
public List<FoodWaveTemplateProduct> getFoodWaveTemplateProductList() {
return foodWaveTemplateProductList;
}
public void setFoodWaveTemplateProductList(List<FoodWaveTemplateProduct> foodWaveTemplateProductList) {
this.foodWaveTemplateProductList = foodWaveTemplateProductList;
}
@Override @Override
public int hashCode() { public int hashCode() {
int hash = 0; int hash = 0;
...@@ -111,4 +105,18 @@ public class FoodWaveTemplate implements Serializable { ...@@ -111,4 +105,18 @@ public class FoodWaveTemplate implements Serializable {
return "fi.insomnia.bortal.model.FoodWaveTemplate[foodWaveTemplatesId=" + foodWaveTemplatesId + "]"; return "fi.insomnia.bortal.model.FoodWaveTemplate[foodWaveTemplatesId=" + foodWaveTemplatesId + "]";
} }
/**
* @return the products
*/
public List<Product> getProducts() {
return products;
}
/**
* @param products the products to set
*/
public void setProducts(List<Product> products) {
this.products = products;
}
} }
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fi.insomnia.bortal.model;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
/**
*
* @author jkj
*/
@Entity
@Table(name = "food_wave_template_products", uniqueConstraints = {
@UniqueConstraint(columnNames = {"food_wave_templates_id", "products_id"})})
@NamedQueries({
@NamedQuery(name = "FoodWaveTemplateProduct.findAll", query = "SELECT f FROM FoodWaveTemplateProduct f"),
@NamedQuery(name = "FoodWaveTemplateProduct.findByFoodWaveTemplateProductsId", query = "SELECT f FROM FoodWaveTemplateProduct f WHERE f.foodWaveTemplateProductsId = :foodWaveTemplateProductsId")})
public class FoodWaveTemplateProduct implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "food_wave_template_products_id", nullable = false)
private Integer foodWaveTemplateProductsId;
@JoinColumn(name = "food_wave_templates_id", referencedColumnName = "food_wave_templates_id", nullable = false)
@ManyToOne(optional = false)
private FoodWaveTemplate foodWaveTemplatesId;
@JoinColumn(name = "products_id", referencedColumnName = "products_id", nullable = false)
@ManyToOne(optional = false)
private Product productsId;
public FoodWaveTemplateProduct() {
}
public FoodWaveTemplateProduct(Integer foodWaveTemplateProductsId) {
this.foodWaveTemplateProductsId = foodWaveTemplateProductsId;
}
public Integer getFoodWaveTemplateProductsId() {
return foodWaveTemplateProductsId;
}
public void setFoodWaveTemplateProductsId(Integer foodWaveTemplateProductsId) {
this.foodWaveTemplateProductsId = foodWaveTemplateProductsId;
}
public FoodWaveTemplate getFoodWaveTemplatesId() {
return foodWaveTemplatesId;
}
public void setFoodWaveTemplatesId(FoodWaveTemplate foodWaveTemplatesId) {
this.foodWaveTemplatesId = foodWaveTemplatesId;
}
public Product getProductsId() {
return productsId;
}
public void setProductsId(Product productsId) {
this.productsId = productsId;
}
@Override
public int hashCode() {
int hash = 0;
hash += (foodWaveTemplateProductsId != null ? foodWaveTemplateProductsId.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof FoodWaveTemplateProduct)) {
return false;
}
FoodWaveTemplateProduct other = (FoodWaveTemplateProduct) object;
if ((this.foodWaveTemplateProductsId == null && other.foodWaveTemplateProductsId != null) || (this.foodWaveTemplateProductsId != null && !this.foodWaveTemplateProductsId.equals(other.foodWaveTemplateProductsId))) {
return false;
}
return true;
}
@Override
public String toString() {
return "fi.insomnia.bortal.model.FoodWaveTemplateProduct[foodWaveTemplateProductsId=" + foodWaveTemplateProductsId + "]";
}
}
...@@ -13,6 +13,9 @@ import javax.persistence.CascadeType; ...@@ -13,6 +13,9 @@ import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
...@@ -48,12 +51,20 @@ public class Product implements Serializable { ...@@ -48,12 +51,20 @@ public class Product implements Serializable {
@Column(name = "barcode", length = 2147483647) @Column(name = "barcode", length = 2147483647)
private String barcode; private String barcode;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "productsId") @OneToMany(cascade = CascadeType.ALL, mappedBy = "productsId")
private List<FoodWaveTemplateProduct> foodWaveTemplateProductList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "productsId")
private List<Place> placeList; private List<Place> placeList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "productsId") @OneToMany(cascade = CascadeType.ALL, mappedBy = "productsId")
private List<AccountEvent> accountEventList; private List<AccountEvent> accountEventList;
@JoinTable(name = "food_wave_templates_products", joinColumns = {
@JoinColumn(name = "products_id", referencedColumnName = "products_id")}, inverseJoinColumns = {
@JoinColumn(name = "food_wave_templates_id", referencedColumnName = "food_wave_templates_id")})
@ManyToMany
private List<FoodWaveTemplate> foodWaveTemplate;
public Product() { public Product() {
} }
...@@ -107,14 +118,6 @@ public class Product implements Serializable { ...@@ -107,14 +118,6 @@ public class Product implements Serializable {
this.barcode = barcode; this.barcode = barcode;
} }
public List<FoodWaveTemplateProduct> getFoodWaveTemplateProductList() {
return foodWaveTemplateProductList;
}
public void setFoodWaveTemplateProductList(List<FoodWaveTemplateProduct> foodWaveTemplateProductList) {
this.foodWaveTemplateProductList = foodWaveTemplateProductList;
}
public List<Place> getPlaceList() { public List<Place> getPlaceList() {
return placeList; return placeList;
} }
...@@ -156,4 +159,18 @@ public class Product implements Serializable { ...@@ -156,4 +159,18 @@ public class Product implements Serializable {
return "fi.insomnia.bortal.model.Product[productsId=" + productsId + "]"; return "fi.insomnia.bortal.model.Product[productsId=" + productsId + "]";
} }
/**
* @return the foodWaveTemplate
*/
public List<FoodWaveTemplate> getFoodWaveTemplate() {
return foodWaveTemplate;
}
/**
* @param foodWaveTemplate the foodWaveTemplate to set
*/
public void setFoodWaveTemplate(List<FoodWaveTemplate> foodWaveTemplate) {
this.foodWaveTemplate = foodWaveTemplate;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!