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

前端 未结 2 587
感动是毒
感动是毒 2020-12-31 18:45

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
         


        
相关标签:
2条回答
  • 2020-12-31 19:16

    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.

    0 讨论(0)
  • 2020-12-31 19:24

    When using HQL, always use proper aliases when performing join operations.Your query should be something like that:

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

    Otherwise if you try to use tbl.entity.someProperty, in HQL, it will always create a crossJoin

    0 讨论(0)
提交回复
热议问题