-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL Query with condition at 4th level class association
PostPosted: Thu May 31, 2007 3:40 am 
Newbie

Joined: Sat Apr 15, 2006 6:02 am
Posts: 4
Hi,

I have a class structure like this
public class Product
{
private productId;
private ProductUse productUse
....
}
public class ProductUse
{
private Set useCategories = new HashSet //Collection of Category
.....
}
public class Category
{
private long categoryId; //primaryKey
private CategoryHead categoryHead;
....
}
public class CategoryHead
{
private long categoryHeadId; //Primary key
....
}

I want to fetch a Product with given productId and categoryHeadId.
I am able to get it by using the below query,
" from Product product where product.productId= :productId
and product.ProductUse.useCategories.categoryId.categoryHead.categoryHeadId :categoryHeadId

But getting error using the query
" from Product product where product.productId= :productId
and product.ProductUse.useCategories.categoryHead.categoryHeadId :categoryHeadId
this gives error saying invalid property 'categoryHeadId'

Anybody can explain how it works in first case(By introducing categoryId) and not in second case ?

Is there any other better way to do this?

Thanks,
Sony M


Top
 Profile  
 
 Post subject: This HQL?
PostPosted: Thu May 31, 2007 12:34 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Code:
from
   Product p
   inner join product.ProductUse pu
   inner join pu.useCategories c
   inner join c.categoryHead h
      with h.categoryHeadId = :categoryHeadId
where
   p.productId = :productId


OR

Code:
from
   Product p
   inner join product.ProductUse pu
   inner join pu.useCategories c
   inner join c.categoryHead h
where
   p.productId = :productId
   and
   h.categoryHeadId = :categoryHeadId


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.