quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

Spring Data API Extension Interface Projections not working with generic interfaces

Open Michael-AT-Corporation opened this issue 2 years ago • 5 comments

Describe the bug

When i have a repository like public interface ParentBaseRepository<T extends ParentBase<C>, C extends ChildBase> extends JpaRepository<T, Long> then the generic C causes the method List<T> findAllTestById(Long id); to throw java.lang.IllegalArgumentException: findAllTestById of Repository at.atc.database.repository.ParentRepository can only use interfaces to map results to non-entity types.. When you remove that function then the function GenericParent<C> findChildrenById(Long id); throws the same exception. Both should work.

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

I don't know if the code to save a parent with children in the reproducer works because i couldn't test it.

Reproducer: reproducerJPAInterfaceMapping.zip I just in case added the spring boot example: SpringBootJpaTestInterfaceMapping.zip

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

Michael-AT-Corporation avatar Jun 27 '23 21:06 Michael-AT-Corporation

/cc @geoand (spring)

quarkus-bot[bot] avatar Jun 27 '23 21:06 quarkus-bot[bot]

This is fixed by #34414

geoand avatar Jun 29 '23 10:06 geoand

@geoand I tried my reproducer with 3.2.1 but it is not working.

Michael-AT-Corporation avatar Jul 20 '23 19:07 Michael-AT-Corporation

@geoand I retestet my reproducer with 3.15.1 and the following function in the ParentBaseRepository fails:

    GenericParent<C> findChildrenById(Long id);

    interface GenericParent<T extends ChildBase> {
        List<T> getChildren();
    }

The error message:

[error]: Build step io.quarkus.spring.data.deployment.SpringDataJPAProcessor#build threw an exception: java.lang.IllegalArgumentException: findChildrenById of Repository at.atc.database.repository.ParentRepository can only use interfaces to map results to non-entity types.
	at io.quarkus.spring.data.deployment.generate.DerivedMethodsAdder.add(DerivedMethodsAdder.java:195)
	at io.quarkus.spring.data.deployment.generate.SpringDataRepositoryCreator.implementCrudRepository(SpringDataRepositoryCreator.java:117)
	at io.quarkus.spring.data.deployment.SpringDataJPAProcessor.implementCrudRepositories(SpringDataJPAProcessor.java:268)
	at io.quarkus.spring.data.deployment.SpringDataJPAProcessor.build(SpringDataJPAProcessor.java:133)
	at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:732)

Michael-AT-Corporation avatar Oct 18 '24 15:10 Michael-AT-Corporation

Thanks for the update

geoand avatar Oct 18 '24 16:10 geoand

cc @aureamunoz

aureamunoz avatar Jan 02 '25 08:01 aureamunoz