Reputation: 676
I got a problem with simple Spring Data issue. Let's assume we got two entities.
public class Request {
// all normal stuff
@ManyToOne
private Document doc;
}
public class Document {
private Long id;
private String name;
}
Simple relation. My question is - is it possible to retrieve Request
entities using Spring Data Method-DSL
and sorting by Document
? So what I want to achieve is to create repository method like:
public List<Request> findAllOrderByDoc()
or similar:
public List<Request> findAllOrderByDocId()
Unfortunately when I try that I am given error message saying that there is no Doc
field or it cannot be mapped to long. I assume it is possible to be done using QueryDSL
and predicates but I am wondering if this pretty obvious and simple thing can be done by plain Spring Data?
Upvotes: 0
Views: 92
Reputation: 10017
Yes, sure.
you need to provide the direction:
public List<Request> findAllOrderByDocAsc()
public List<Request> findAllOrderByDocDesc()
Upvotes: 1