spring-projects / spring-projects/spring-data-relational

Issue with Column Alias mapping to projection in R2dbcRepository Query

Open
#1,757 0 comments 0 reactions 1 assignee View on GitHub

@mp911de is already working on this.

Since Apr 15, 2024.

in: r2dbc status: waiting-for-triage
Dominant language
Java
Stars
827
Forks
394
PR merge metrics
No merged PRs in 30d

Description

Hi Team,

I have created this query in repository with appropriate java class for projection. When query is executed, i am getting null in walmartYearWeek.

@Query("""
           SELECT DISTINCT ON (com_yr_wk) com_yr_wk as walmart_year_week, com_start_date as walmart_week_start_date
           FROM calendar_meta
           WHERE calendar_date BETWEEN :startDate AND :endDate
           ORDER BY com_yr_wk
            """)
    Flux<WalmartCalendarWeek> findWalmartYearWeekDistinctByDateBetween(LocalDate startDate, LocalDate endDate);
@Data
@AllArgsConstructor
@NoArgsConstructor
public class WalmartCalendarWeek {

        Integer walmartYearWeek;
        LocalDate walmartWeekStartDate;
}

Then, i tried following query and class and now the value is coming as expected in walmarYearWeek.

@Query("""
           SELECT DISTINCT ON (com_yr_wk) com_yr_wk as walmar_year_week, com_start_date as walmart_week_start_date
           FROM calendar_meta
           WHERE calendar_date BETWEEN :startDate AND :endDate
           ORDER BY com_yr_wk
            """)
    Flux<WalmarCalendarWeek> findWalmarYearWeekDistinctByDateBetween(LocalDate startDate, LocalDate endDate);
@Data
@AllArgsConstructor
@NoArgsConstructor
public class WalmarCalendarWeek {

        Integer walmarYearWeek;
        LocalDate walmartWeekStartDate;
}

To conclude, walmart_year_week alias is not working but walmar_year_week or any other alias works

NOTE: Above issue is not there with org.springframework.boot:spring-boot-starter-parent:3.2.0.

I have created sample repo to reproduce this behaviour
https://github.com/jaykakkad69/r2dbc-demo

  • Added a data.sql file to create database and populate test data
  • There are two end points to test each query
  • Please change the credentials accordingly in PostgresConfiguration

Thanks.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.