Specification
@query on non-repository interfaces
I need clarification on ...
The TCK has this hidden treasure:
public interface DepartmentQueries<T> {
@Query("where department = :dept order by name")
List<T> findByDepartment(@Param("dept") String department);
@Query("select count(*) where department = :dept")
long countByDepartment(@Param("dept") String department);
@Query("where name like :pattern order by name")
List<T> searchByName(@Param("pattern") String pattern);
}
@Repository
public interface ProjectRegistry extends DataRepository<Project, Long>, DepartmentQueries<Project> {
@Save
void save(Project project);
@Query("where budget > :min order by name")
List<Project> fundedAbove(@Param("min") double min);
}
Let us now consider this gem of a method declaration in all its radiant glory:
@Query("where department = :dept order by name")
List<T> findByDepartment(@Param("dept") String department);
From the signature, we infer the query:
from T t where t.department = :dept order by t.name
But the generic type T cannot possibly have fields named department and name.
Oh, but a concrete argument to T might happen to be the class Project which just happens by complete coincidence to have such fields, so it's OK, right?
No. No, it's not okay. That's not how types work.
We should clarify in the spec that this is not supported, and we should delete the code from the TCK.
Additional information
UPDATE: Sorry! The TCK does not contain the code above! See comments below.
Specification
@query on non-repository interfaces
I need clarification on ...
The TCK has this hidden treasure:
Let us now consider this gem of a method declaration in all its radiant glory:
From the signature, we infer the query:
But the generic type
Tcannot possibly have fields nameddepartmentandname.Oh, but a concrete argument to
Tmight happen to be the classProjectwhich just happens by complete coincidence to have such fields, so it's OK, right?No. No, it's not okay. That's not how types work.
We should clarify in the spec that this is not supported, and we should delete the code from the TCK.
Additional information
UPDATE: Sorry! The TCK does not contain the code above! See comments below.