我正在尝试使用HQL使用JOIN FETCH获取我的实体以及子实体,如果我想要所有结果,这是正常工作但如果我想要一个页面则不是这样
我的实体是
@Entity
@Data
public class VisitEntity {
@Id
@Audited
private long id;
.
.
.
@OneToMany(cascade = CascadeType.ALL,)
private List<VisitCommentEntity> comments;
}
Run Code Online (Sandbox Code Playgroud)
因为我有数百万次访问,我需要使用Pageable,我想在单个数据库查询中获取注释,如:
@Query("SELECT v FROM VisitEntity v LEFT JOIN FETCH v.comments WHERE v.venue.id = :venueId and ..." )
public Page<VisitEntity> getVenueVisits(@Param("venueId") long venueId,...,
Pageable pageable);
Run Code Online (Sandbox Code Playgroud)
该HQL调用抛出以下异常:
Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=null,role=com.ro.lib.visit.entity.VisitEntity.comments,tableName=visitdb.visit_comment,tableAlias=comments1_,origin=visitdb.visit visitentit0_,columns={visitentit0_.visit_id ,className=com.ro.lib.visit.entity.VisitCommentEntity}}] …Run Code Online (Sandbox Code Playgroud)