I have what hopefully is a very simple question. I am aiming to filter a result set and am not sure of how to accomplish it using the Hibernate Query Language which I am not very familiar with. (I know SQL very well but not HQL). I have 3 entities, Product, Store, and ShoppingCenter. Logically speaking, a "ShoppingCenter" consists of 1 or more "Stores" and a "Store" contains 1 or more "Products". I would like to do a query that returns all "Stores" within a specified "ShoppingCenter" that carry a given "Product".
The following code will return to me all "Stores" that carry a given "Product".
Code:
select gmStores as gmStores from Product as gmProduct where gmProduct.productId = 5
However, I would like to add a "where clause" that filters that result set to only those "Stores" in a specified "ShoppingCenter". I tried the following but received an "Invalid Path" Syntax Exception referencing "gmStores.shoppingCenter.shoppingCenterId":
Code:
select gmStores as gmStores from Product as gmProduct where gmStores.shoppingCenter.shoppingCenterId = 1 and gmProduct.productId = 5
Can someone please help me out with this ?
Following are snippets of the class definitions for these 3 entities. Thanks.
Code:
public class Product implements java.io.Serializable
{
...
private int productId;
private Set gmStores = new HashSet(0);
...
}
Code:
public class Store implements java.io.Serializable
{
...
private int storeId;
private ShoppingCenter shoppingCenter;
...
}
Code:
public class ShoppingCenter implements java.io.Serializable
{
...
private int shoppingCenterId;
...
}