我试图用hibernate编写jpql查询。我在@Repository中有这样的查询

@Query(value = "select p from Product p inner join ProductsUser pu on p.prosuctId = pu.productId where pu.userId = :uuid")

但我有个例外
Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join! [select p from com.example.api.dto.ProductDto p inner join ProductsUsersDto pu on p.prosuctId = pu.productId where pu.userId = :uuid]

最佳答案

您不需要指定JOIN ... ON-子句,因为它已经在实体类中配置。所以查询比较简单,如下所示:

@Query("select p from Product p join p.productsUser pu where pu.userId = :uuid")

10-04 23:21