I use JpaRepositoryboth JpaSpecificationExecutorfrom Spring Data and I had a problem sorting a methodfindAll(specification, pageable, sort)
I want to sort the result of a specification using an attached property from the main repo class. This is my case:
main class
class Foo {
@OneToMany(mappedBy="foo")
private Set<Bar> bars;
}
ordering class
class Bar {
@ManyToOne
@JoinColumn(name="fooId")
private Foo foo;
@Column
private Date date;
}
and this is my repo
interface FooRepo extends JpaRepository<Foo , Long>,
JpaSpecificationExecutor<Foo>{
}
this is how i try to arrange this result
void anymethod(){
Sort sort = new Sort(Bar_.date.getName());
PageRequest pr = new PageRequest(anyPage, anyMaxResultsNum, sort);
repository.findAll(anySpecification, pr);
}
and when I run this, I get "PropertyReferenceException: no property date for type Foo!"
How can i do this?
source
share