SEAM entityQuery
ypasmk Aug 19, 2009 1:21 PMHi, I have two entity beans
Entity person
package panda.entities;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import org.jboss.seam.annotations.Name;
@Entity
@Name("product")
public class Product implements Serializable{
/**
*
*/
private static final long serialVersionUID = -5249249029210862738L;
private long id;
private String p_id;
public String getP_id() {
return p_id;
}
public void setP_id(String p_id) {
this.p_id = p_id;
}
private String name;
private String description;
private double price;
private String serial;
private float fpa;
private int quantity;
private List<Image> images;
private List<ProductFile> files;
private List<ProductCategory> categories;
private Manufacturer manufacturer;
public Product() {}
@Id @GeneratedValue
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public float getFpa() {
return fpa;
}
public void setFpa(float fpa) {
this.fpa = fpa;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
@OneToMany(fetch=FetchType.LAZY)
public List<Image> getImages() {
return images;
}
public void setImages(List<Image> images) {
this.images = images;
}
@OneToMany(fetch=FetchType.LAZY)
public List<ProductFile> getFiles() {
return files;
}
public void setFiles(List<ProductFile> files) {
this.files = files;
}
@OneToMany
public List<ProductCategory> getCategories() {
return categories;
}
public void setCategories(List<ProductCategory> categories) {
this.categories = categories;
}
@OneToOne
public Manufacturer getManufacturer() {
return manufacturer;
}
public void setManufacturer(Manufacturer manufacturer) {
this.manufacturer = manufacturer;
}
public String getSerial() {
return serial;
}
public void setSerial(String serial) {
this.serial = serial;
}
}
Entity ProductCategory
package panda.entities; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToMany; import javax.persistence.OneToMany; import javax.persistence.Transient; @Entity public class ProductCategory implements Serializable{ /** * */ private static final long serialVersionUID = -4153730233730145549L; private int id; private String name; private List<ProductCategory> productCategory; private boolean hasParent; private int parentid; public int getParentid() { return parentid; } public void setParentid(int parentid) { this.parentid = parentid; } public boolean isHasParent() { return hasParent; } public void setHasParent(boolean hasParent) { this.hasParent = hasParent; } @Id @GeneratedValue public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public void setProductCategory(List<ProductCategory> productCategory) { this.productCategory = productCategory; } @OneToMany @JoinColumn(name="category_id") public List<ProductCategory> getProductCategory() { return productCategory; } @Transient public void addSubCat(ProductCategory buff) { if(productCategory!=null) { productCategory.add(buff); }else { productCategory=new ArrayList<ProductCategory>(); productCategory.add(buff); } } @Override public String toString() { return this.name; } }
so I want to query all the products that belongs to a specific category?how can I do that?