Hi all,
I'm a newbie to HQL \ EJBQL, and I hoping to get some help with the right way of composing a query string:
(It's a Seam project)
a Sale has a List of Items:
Code:
@Entity
@Name("sale")
public class Sale extends MyEntity {
private List<Item> items = new ArrayList<Item>();
...
@OneToMany(cascade =
{CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE},
mappedBy="sale")
@org.hibernate.annotations.Cascade(value=
{org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
public List<Item> getItems() {
return items;
}
...
}
An Item is nothing more than a bridge between a Sale and a Product - it references one of each and specifies the amount purchased:
Code:
@Entity
@Name("item")
public class Item extends MyEntity implements MyProxy<Item> {
Product product;
Sale sale;
Integer amount;
@NotNull
public Product getProduct() {
return product;
}
@NotNull
@ManyToOne
public Sale getSale() {
return sale;
}
...
}
And a Product, by the way, has no awareness of either Sales or Items:
Code:
@Entity
@Name("product")
public class Product extends MyEntity {
private String name;
private String model;
....
}
SO: Given some product X, What would be the query string to
Code:
Get all Sales that have an Item in them whose Product is X
??
Also if anyone can direct me to a good EjbQL learning resource,
that would be great. Thanks.