query specified join fetching, but the owner of the fetched association was not present in the select list
在使用EntityGraph查询时报了这个错误,它的意思是说@EntityGraph
中制定的某个属性没有在结果集中出现。该方法的代码如下:
@EntityGraph(attributePaths={"staff"},type=EntityGraphType.FETCH)
@Query("from Account")
public List<Account> findAll();
后来发现查询出来的结果集中,会出现staff
为空的记录,因此只需要将查询语句改成@Query("from Account where staff != null")
就能解决该问题。