AOT compilation fails for derived delete queries returning Set
AOT repository fragment generation produces invalid Java code for derived delete methods returning Set.
Steps to reproduce
Declare a repository method returning Set and generate its AOT fragment:
Set<User> deleteByLastname(String lastname);
The generated method contains code equivalent to:
public Set<User> deleteByLastname(String lastname) {
// Query and remove matching entities…
return (List) convertOne(resultList, false, Set.class);
}
Expected behavior
The generated method compiles and returns the deleted entities as a Set<User>.
Actual behavior
Compilation fails with:
incompatible types: java.util.List cannot be converted to
java.util.Set<org.springframework.data.jpa.domain.sample.User>
Cause
In JpaCodeBlocks, the isSet(methodReturn) branch for derived delete queries uses List.class for the return cast. This generates return (List) convertOne(resultList, false, Set.class);, which is incompatible with the method's declared return type, Set<User>.
Reproduced on 4.2.0-SNAPSHOT using an AOT integration test.
Please refrain from pasting images of code and test execution. They are neither indexable nor helpful.
Got it, thanks! I've replaced the screenshots with code blocks.