unnecessary join in subquery
Hi,
for the following hql query hibernate generates a sql statement with an unnecessary join in the subselect
Code:
select count(distinct pnode.productid) from ProductNode pnode where pnode.id in (select attribute.productNode from Attribute attribute where attribute.name = ? and attribute.val = ?)
Results in following SQL
Code:
select count(distinct productnod1_.productid) from product_node productnod1_ where productnod1_.id in (select attribute2_.product_node_id from attribute attribute2_, product_node productnod3_ where attribute2_.product_node_id=productnod3_.id and attribute2_.name='Bauart' and attribute2_.val='Barebone-PC')
The subquery on the Attribute table joins unnecessary the product_node table.
The code in grails for my domain classes:
Code:
class ProductNode {
List<Attribute> attrs
}
class Attribute {
String name
String val
static belongsTo = [productNode: ProductNode]
}
I have shorten the domain class code and queries to hopefully relevant parts of my problem. In truth I dynammically append more subselects to get all productnodes that matches an attribute list and productnode is in truth a tree like structure...
Is there a trick to tell hibernate not to use the unnecessary join?
Can someone confirm, that this happens in a pure java (non grails) environment too?
Best regards,
pddd