Hi,
I've created the HQL query down below and it gives me the SQL listed even further down. The problem is that it requires the rule to have a relation to a category with this SQL
Code:
and R.id=RC.id_rule
and RC.id_category=C.id 
and I don't think this condition is reflected in the HQL query?!
I guess the problem is due to the 
Code:
or r.categories.id in (select ...
So I guess I have to modify this to something like
Code:
or ONE OF r.categories IS CONTAINED IN (select ...
Am I right? Is this possible?
Thanks
Alex
Hibernate version: 3.1 and 3.2.1
Mapping documents:Would be many... but I don't think this is mapping related...
Code between sessionFactory.openSession() and session.close():Code:
Only the important part:
select distinct r, s.weight, index(r) 
from ProductDiscountRuleSet s inner join s.rules r 
where ( (s.from = null and s.until = null)    
      or :now between s.from and s.until ) 
   and ( :customer in elements(r.customers)    
      or :priceFamily in elements(r.priceFamilies) ) 
   and ( :product in elements(r.products)    
      or (select p.brand from ProductI18N p join p.productReferences pr join pr.productReference prr where prr = :product) in elements(r.brands)    
      or r.categories.id in (select c.id from Category c join c.products cp join cp.productReferences cpr join cpr.productReference cprr where cprr = :product) ) 
order by s.weight, index(r) 
Full stack trace of any exception that occurs:None
Name and version of the database you are using:Postgresql 8.1
The generated SQL (show_sql=true):Code:
select distinct R.id as col_0_0_, RS.weight as col_1_0_, R.ord as col_2_0_, R.id as id41_, R.version as version41_, R.stackable as stackable41_, R.last as last41_, R.discount as discount41_, R.fixed_amount_discount as fixed7_41_, R.fixed_price as fixed8_41_, R.base_price as base9_41_, R."unique" as unique10_41_, R.promotion as promotion41_, R.min_amount as min12_41_, R.free_shipping as free13_41_, R.paymentDelay as payment14_41_, R.discount_ref as discount15_41_, R.delay_ref as delay16_41_, R.type as type41_ 
from rule_sets RS inner join rules R 
   on RS.id=R.id_rule_set, rules_categories RC, categories C 
where 
RS.type='P' 
and R.id=RC.id_rule 
and RC.id_category=C.id 
and ((RS."from" is null) 
   and (RS.until is null) 
   or ? between RS."from" and RS.until)
and (? in (select RuleCust.id_customer 
      from rules_customers RuleCust 
      where R.id=RuleCust.id_rule) 
   or ? in (select RulePriceFam.id_price_family 
      from rules_price_families RulePriceFam 
      where R.id=RulePriceFam.id_rule)) 
and (? in (select RuleProd.id_product 
         from rules_product_references RuleProd 
         where R.id=RuleProd.id_rule) 
   or (select P.id_brand 
         from products P inner join product_options O 
               on P.id=O.id_product inner join product_references R 
               on O.id_product_reference=R.id 
         where R.id=?) 
      in (select RuleBrand.id_brand 
         from rules_brands RuleBrand 
         where R.id=RuleBrand.id_rule) 
   or C.id in (select C.id 
         from categories C inner join products_catalogs PC 
               on C.id=PC.id_category inner join products P 
               on PC.id_product=P.id inner join product_options PO 
               on P.id=PO.id_product inner join product_references PR 
               on PO.id_product_reference=PR.id 
         where PR.id=?))
order by RS.weight, R.ord
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this: 
http://hibernate.org/42.html