spring-data-jpa icon indicating copy to clipboard operation
spring-data-jpa copied to clipboard

AOT compilation fails for derived delete queries returning Set

Open ryujungkyun opened this issue 1 month ago • 2 comments

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.

ryujungkyun avatar Oct 14 '26 03:10 ryujungkyun

Please refrain from pasting images of code and test execution. They are neither indexable nor helpful.

mp911de avatar Oct 15 '26 08:10 mp911de

Got it, thanks! I've replaced the screenshots with code blocks.

ryujungkyun avatar Oct 15 '26 08:10 ryujungkyun