我正在使用Spring Data中的JpaRepository
和JpaSpecificationExecutor
,但是在对方法进行findAll(specification, pageable, sort)
排序时遇到了问题。
我想按照主存储库类中的嵌套属性对规范的结果进行排序。这是我的情况:
主要的类:
class Foo {
//other properties
@OneToMany(mappedBy="foo")
private Set<Bar> bars;
}
订单类
class Bar {
@ManyToOne
@JoinColumn(name="fooId")
private Foo foo;
//I WANT TO SORT BY THIS FIELD
@Column
private Date date;
}
这是我的代码库
interface FooRepo extends JpaRepository<Foo , Long>,
JpaSpecificationExecutor<Foo>{
//just jparepo methods
}
这是我尝试对结果进行排序的方式
void anymethod(){
Sort sort = new Sort(Bar_.date.getName());
PageRequest pr = new PageRequest(anyPage, anyMaxResultsNum, sort);
repository.findAll(anySpecification, pr);
}
我运行代码时出现了"PropertyReferenceException: No property date found for type Foo!"的错误信息,应该怎么办?