HQL left join: Path expected for join

后端 未结 1 1699
感情败类
感情败类 2020-12-29 09:20

I am new at Hibernate, and I have a question regarding HQL Left join.

I try to left join 2 tables, patient and provider, and keep getting \"Path expected for join!\"

相关标签:
1条回答
  • 2020-12-29 09:57

    Your patient has a reference to the provider, and also has the provider id as a property. I would probably get rid of the provider id property on the patient and just have the reference to the provider. Then your query should be something like this.

    select pat.patientId, pat.patientName 
    from patient as pat 
    left join pat.provider as pro
    

    To join, you need the association path from your patient to your provider, which in this case is pat.provider. Then hibernate will automatically use the "column" specified in the many-to-one mapping to join into the provider table. In your case, the join doesn't make a lot of sense since you aren't querying on any properties of the provider, so something like this might make more sense

    select pat 
    from patient as pat 
    join pat.provider as pro 
    where pat.patientName = 'John' 
    and pro.name = 'United Healthcare'
    

    There you are able to filter your patient list to patients named John that have United Healthcare as the provider.

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