I want to get sorted list of Model
s for a given set of Car
vins. The following repository query attempts to do this:
@Query("select distinct c.model"
+ "from Car c "
+ "where c.id in :vins")
public Set<Model> findDistinctModelForCarIdsIn(@Param("vins") Set<Integer> vins, Sort sort);
But it appears sort does not work if I put this in a ModelRepository
:
http://localhost/api/models/search/findDistinctModelForCarIdsIn?vins=16203,25617,42661&sort=model.name,asc
If instead I put findDistinctModelForCarIdsIn
in CarRepository
, the sort works:
http://localhost/api/cars/search/findDistinctModelForCarIdsIn?vins=16203,25617,42661&sort=model.name,asc
Why is this? Is the rule to put the method in the repository corresponding to the entity that I selecting from (e.g., Car
) instead of the what I'm selecting (e.g., Model
)?
Here are my domain objects:
class Car {
Integer id;
@ManyToOne
Model model;
}
class Model {
Integer id;
String name;
}