Why do I get an invalid path when I try and construct a JPQL join query?

前端 未结 2 1241
忘了有多久
忘了有多久 2021-01-16 05:36

I’m using JPA 2.1, Hibernate 4.3.6.Final, and MySQL 5.5.37. How do I write a JPQL query that does a join? I’m trying below

    final String jpqlQuery = \"S         


        
2条回答
  •  有刺的猬
    2021-01-16 05:44

    The issue reported by Hibernate is in the first row:

    final String jpqlQuery = "SELECT m FROM Message m LEFT JOIN MessageReadDate mr "...
    

    in the LEFT JOIN statement. In hql, the JOIN must be expressing the relation, e.g.

    LEFT JOIN m.MessageReadDate mr // the m is referencing the MessageReadDate
    

    If there is no reference, we can still use that, but with Cartesian product

    FROM Message m, MessageReadDate mr
    

    in that case, the CROSS JOIN will be issued

    See the:

    • 16.2. The from clause

    small cite:

    Multiple classes can appear, resulting in a cartesian product or "cross" join.

    from Formula, Parameter
    from Formula as form, Parameter as param
    
    • 16.3. Associations and joins

    You can also assign aliases to associated entities or to elements of a collection of values using a join. For example:

    from Cat as cat
        inner join cat.mate as mate
    

提交回复
热议问题