Question

I am little confuse while fetching products in HQL. Product has multiple SKUs and SKU has multiple availibility.. Below is my hql query.

select distinct p from Product p 
join p.skus sku
join sku.availibility a
where sku.skuType = "DEFAULT" AND a.available = true && a.day = 5;

I have to filter the products where skuType is "DEFAULT" and availiblity of only that sku("DEFAULT" type).
I am confused because.. I am thinking in above query available and a.day part will check in all the skus not just the default sku..
How this query behave ? Am i wrong ? IF yes then how can be query structured for this ?

Thanks, Ankit

Was it helpful?

Solution

No, Your query will only return a set of products P, where each e in P matches the following:

  1. e has a SKU which has skuType="DEFAULT" AND
  2. e has a SKU which is skuType="DEFAULT" AND that SKU has availability a WHERE a.available = true && a.day = 5

Your comment

I am thinking in above query available and a.day part will check in all the skus not just the default sku..

Yes, It the query execution will loop through your CROSS JOIN set, but it will ONLY RETURN products that match the conditions given above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top