spring-projects / spring-data-jpa

Simplifies the development of creating a JPA-based data access layer.
https://spring.io/projects/spring-data-jpa/
Apache License 2.0
3.03k stars 1.43k forks source link

When querying using a projection interface and the entity implements said interface than it tries to convert an array to the projection interface [DATAJPA-1644] #1947

Open spring-projects-issues opened 4 years ago

spring-projects-issues commented 4 years ago

Mark Czubin opened DATAJPA-1644 and commented

When we create a projection query (i.e. use an interface to denote which fields we want to fetch). And the entity of the repo implements the interface as well. Then we are unable to execute the query in the repository of the entity. 

The same query does work in other repositories.

 

class X implements Y { 
... lots of fields 
}
interface Y { 
   String getMyField 
}
interface xRepo implements JpaRepository<X, ID> {    
   @Query("select x.myField as myField from X x")    
   List<Y> selectProjection(); 
}

 

This query yields the following error message:

No converter found capable of converting from type [java.lang.String] to type[@org.springframework.data.jpa.repository.Query Y]

 

Workaround:

Place the query in a different repository. 

 

Added as attachment a maven project with the problem and workaround.

 


Attachments:

vboerchers commented 2 months ago

Thank you for creating this issue. The problem is still present in spring-data-jpa:3.3.2