These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate Query for filtering a Set
PostPosted: Thu Dec 10, 2009 8:35 pm 
Newbie

Joined: Sat Nov 22, 2008 1:35 pm
Posts: 7
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;
     ...
}


Top
 Profile  
 
 Post subject: Re: Hibernate Query for filtering a Set
PostPosted: Fri Dec 11, 2009 4:41 am 
Senior
Senior

Joined: Tue Aug 04, 2009 7:45 am
Posts: 124
select distinct p.store
from myschema.Product p
where p.store.shoppingcenter = :shoppingcenter
and p = :product


Top
 Profile  
 
 Post subject: Re: Hibernate Query for filtering a Set
PostPosted: Fri Dec 11, 2009 5:24 pm 
Newbie

Joined: Sat Nov 22, 2008 1:35 pm
Posts: 7
Dmitry Geraskov wrote:
select distinct p.store
from myschema.Product p
where p.store.shoppingcenter = :shoppingcenter
and p = :product


That doesn't work because "p.store" is a "Set" of stores rather than a single store which could be de-referenced by using "p.store.shoppingcenter". The above also generates an "Invalid Path" error.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.