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
2.98k stars 1.41k forks source link

Page's content type isn't correct #3379

Closed FULaBUla closed 7 months ago

FULaBUla commented 7 months ago
@Query("select .....")
Page<LinkedHashMap<String, Object> query(Pageable pageable);

I wish spring-data-jpa return Page<LinkedHashMap<String, Object>> but you return Page<Object[]>. The content type isn't LinkedHashMap<String, Object>, it is Object[].

christophstrobl commented 7 months ago

If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it. Right now, we struggle to understand what you want to achieve.

FULaBUla commented 7 months ago

If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it. Right now, we struggle to understand what you want to achieve.

According to the method I defined, the return value type I should get from Page.getContent() is LinkedHashMap<String, Object>. But actually, I get Object[] from Page.getContent().

mp911de commented 7 months ago

We do not support Map as query method return type, see https://docs.spring.io/spring-data/data-jpa/reference/repositories/query-return-types-reference.html.

FULaBUla commented 7 months ago

We do not support Map as query method return type, see https://docs.spring.io/spring-data/data-jpa/reference/repositories/query-return-types-reference.html.

@mp911de The documentation doesn't specify what type of T is available in Page<T>. And when I use Page<List<Object>>, The type i get from Page.getContent() is also Object[] instead of List.

mp911de commented 7 months ago

It does:

T A unique entity.

A Map is not an entity.

FULaBUla commented 7 months ago

It does:

T A unique entity.

A Map is not an entity.

I know, but when I use Page<List<Object>>, The type i get from Page.getContent() is also Object[] instead of List.

And I remember that in the previous version, spring-data-jpa could use map, where the key value was the name of the column, and the value was the corresponding value of the column.

@mp911de