Jpa namedquery with left join fetch

后端 未结 2 888
独厮守ぢ
独厮守ぢ 2021-01-13 07:58

this is my namedquery:

@NamedQuery( name = \"User.findOneWithLists\", query = \"SELECT u FROM User u \"

2条回答
  •  时光说笑
    2021-01-13 08:06

    For join conditions Hibernate provides the with keyword, even before JPA 2.1.

    The relevant part of your query thus would look like this:

    SELECT u FROM User u  ... LEFT JOIN u.st WITH st.deleted = false
    

    I'm not sure about LEFT JOIN FETCH u.cl with u.id= :id but if I remember correctly, that's not as easy and might have to be resolved with an adapted join and u.ui = :id in the where condition.

    LEFT JOIN FETCH u.st WITH st.deleted = false`

    This is not supported, since you can't do a partial fetch.

提交回复
热议问题