Search code examples
hibernatehql

HQL implicit join in where clause generate cross join instead of inner join


I'm using Hibernate 3.6 and MSSQL 2012.

When executing this HQL

select tbl.state from Property tbl where tbl.state = 1 and tbl.entity.state = 1 and
tbl.entity.className = 'com....' and tbl.fieldName = 'fieldName'

I'm getting this SQL

select property0_.State as col_0_0_ from Properties property0_ cross join Entities
entity1_ where property0_.refEntityid=entity1_.id and property0_.State=1 and
entity1_.State=1 and entity1_.ClassName='com....' and property0_.FieldName='fieldName'

*Notice the cross join and the added condition in the where clause.

According to Hibernate docs https://docs.jboss.org/hibernate/core/3.5/reference/en/html/queryhql.html#queryhql-joins-forms

implicit join should generate to inner join.

I've noticed that there is an open bug https://hibernate.atlassian.net/browse/HHH-7707 that may be referring to this problem but no one answered and it's opened for a year already.

I would appreciate any information about this issue. Thank you.

PS. I'm well aware that using implicit joins is not the right way of writing HQL but I can't do anything about this right now.


Solution

  • Your join is an inner join, but using the old syntax consisting in adding a condition in the where clause:

    where property0_.refEntityid=entity1_.id
    

    instead of doing it with

    inner join Entities entity1_ on property0_.refEntityid=entity1_.id
    

    The result is exactly the same.

    And using implicit joins in HQL is not a problem at all, as long as you understand what they're doing.