Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL column name resolution failed for embeddable with AggregateReference #1695

Closed
jipipi opened this issue Dec 12, 2023 · 0 comments
Closed
Assignees
Labels
type: regression A regression from a previous release

Comments

@jipipi
Copy link

jipipi commented Dec 12, 2023

The sql query is not generate with the right column name for embedded AggregateReference property. The embedded prefix definition is not set.

Example :

public record Parent(
        @Id Long id,
        String name,
        @Embedded.Nullable(prefix = "nested_")
        Nested nested
){}

public record Nested(
        AggregateReference<Child,Long>  child_id, // ko when generate sql query (select)
        String type
){}

public record Child(
   @Id Long id,
   String name) {}
CREATE TABLE IF NOT EXISTS Parent (
    id INTEGER IDENTITY PRIMARY KEY,
    name VARCHAR(100),
    nested_child_id NUMERIC,
    nested_type VARCHAR(100)
);

CREATE TABLE IF NOT EXISTS Child (
                                   id INTEGER IDENTITY PRIMARY KEY,
                                   name VARCHAR(100)
);

A simple loading of parent will generate the issue (the save is ok) :

 var parent = repository.findById(1L)//failed because sql query is not correct the embedded prefix is missing: "PARENT"."CHILD_ID" must be "PARENT"."NESTED_CHILD_ID"

SQL generated : SELECT "PARENT"."ID" AS "ID", "PARENT"."NAME" AS "NAME", "PARENT"."NESTED_TYPE" AS "NESTED_TYPE", "PARENT"."CHILD_ID" AS "CHILD_ID" FROM "PARENT" WHERE "PARENT"."ID" = ?

Here project to reproduce error : Test project

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 12, 2023
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 13, 2023
@mp911de mp911de assigned schauder and mp911de and unassigned schauder Dec 13, 2023
@mp911de mp911de added type: regression A regression from a previous release and removed type: bug A general bug labels Dec 14, 2023
@mp911de mp911de changed the title SQL column name resolution failed for Embedded with AggregateReference SQL column name resolution failed for embeddable with AggregateReference Dec 14, 2023
@mp911de mp911de added this to the 3.2.1 (2023.1.1) milestone Dec 14, 2023
mp911de added a commit that referenced this issue Dec 14, 2023
Remove duplicate and unused code.

See #1695
mp911de added a commit that referenced this issue Dec 14, 2023
We now also wrap associations to ensure embedded prefix propagation.

Closes #1695
mp911de added a commit that referenced this issue Dec 14, 2023
Remove duplicate and unused code.

See #1695
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

4 participants