Jpa namedquery with left join fetch

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

this is my namedquery:

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

2条回答
  •  粉色の甜心
    2021-01-13 08:10

    Check a SQL syntax, you can't use left join after where clause. If you are looking at the SQL generated form that named query you will see that joined tables in the query the where clause comes after joins and should specify equal condition that links those tables by the keys. The primary key of the main table on the left and the foreign key of the joined table on the right. The joined table is specified by the property of your many-to-one association.

    @NamedQuery(
        name = "findOneWithLists",
        query = "from Table t left join User u where u.id= :id"
    )
    

提交回复
热议问题