Description
Consider a repository query method declaration like this:
interface SomeRepository extends Repository<SomeAggregate, …> {
@Query("some query using `type` as parameter")
<T extends SomeAggregate> Collection<T> findOnlySpecificSubTypes(Class<T> type);
}
The query method intends to find only subtypes of SomeAggregate
and the type being defined by the type
parameter. Unfortunately, it is currently always considered a dynamic projection parameter, even if we are not dealing with a projection here.
The decision whether a parameter is considered a dynamic projection one is currently held in Parameter
which as of now, unfortunately, doesn't know anything about the primary aggregate type. If it had that, we could back out of any projection considerations once we realize the Class
' component type is tied to that.
A different approach could be to disregard a Class
parameter annotated with @Param
as projection parameter. The annotation currently requires a value to be set, which makes it a bit cumbersome to use, as you'd need to repeat the parameter name unconditionally. I am not sure whether making that optional would be a big issue.