Skip to content

Questions on projection/DTO nesting #633

Closed
@cambierr

Description

@cambierr

Hi,

Based on https://docs.spring.io/spring-data/r2dbc/docs/current/reference/html/#projections I understand that nesting is supposed to work, which I'm about to investigate but I'm wondering how this is actually working and what's allowed.

First, given a tables A(col_a1, col_a2) and B(col_b1, col_b2, col_a1), the last column of B being a foreign key to A.col_a1. The documentation seems to say that something like

class A{
    String colA1;
    String colA2;
    B b;

    static class B{
        String colB1;
        String colB2;
    }
};

interface ARepository extends Repository<A, String> {
    Flux<A> findBycolA1(String colA1);
}

How is this supposed to be mapped to a + a.b ?

I guess we should build something like

interface ARepository extends Repository<A, String> {
    @Query("SELECT * FROM A WHERE col_a1 = :colA1 join B on a.colA1 = b.colA1")
    Flux<A> findBycolA1(String colA1);
}

and I can understand that the mapping would work using this model. Would it be right ?

A final question would then be; if 1-to-1 mapping works, should 1-to-n mapping work too ? If so, under which conditions ?

Thank you already, guys.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions