Skip to content

Invalid DELETE created in derived query #2123

Open

Description

@chanhyeong

Issue

If child object has an id column which named different with parent's id,
an invalid DELETE query created and failed to execute the test JdbcRepositoryWithCollectionsChainHsqlIntegrationTests#deleteByName.
(in 3.5.x, 4.0.0-M versions)

I reproduced in commit chanhyeong@7cca9ee, and it creates an error message below.

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [DELETE FROM "GRAND_CHILD_ELEMENT" WHERE "GRAND_CHILD_ELEMENT"."CHILD_ELEMENT" IN (SELECT "CHILD_ELEMENT"."ID" FROM "CHILD_ELEMENT" WHERE "CHILD_ELEMENT"."DUMMY_ENTITY" IN (SELECT "DUMMY_ENTITY"."ID" FROM "DUMMY_ENTITY" WHERE "DUMMY_ENTITY"."NAME" = ?))]

Here is the query in message to read easily.

DELETE FROM
  "GRAND_CHILD_ELEMENT"
WHERE
  "GRAND_CHILD_ELEMENT"."CHILD_ELEMENT" IN (
    SELECT
      "CHILD_ELEMENT"."ID"
    FROM
      "CHILD_ELEMENT"
    WHERE
      "CHILD_ELEMENT"."DUMMY_ENTITY" IN (
        SELECT
          "DUMMY_ENTITY"."ID"
        FROM
          "DUMMY_ENTITY"
        WHERE
          "DUMMY_ENTITY"."NAME" = ?
    )
  )

Expected

It should select "CHILD_ELEMENT"."CHILD_ID" in first IN statement, instead of "CHILD_ELEMENT"."ID".

Resolution

If JdbcDeleteQueryCreator#deleteRelation takes the id column of current path on SELECT phrase, this issue will be fixed.

If I misunderstood the operation, please let me know.

Activity

  1. self-assigned this
    on Aug 19, 2025
  2. Huiyeongkim commented on Aug 26, 2025

    @Huiyeongkim

    Hi @chanhyeong, I’m interested in contributing to this issue!

  3. schauder commented on Aug 26, 2025

    @schauder
    Contributor

    You are welcome to. Let me know if you need help.

  4. chanhyeong commented on Aug 27, 2025

    @chanhyeong
    ContributorAuthor

    @Huiyeongkim
    I've been waiting a comment from maintainers, but it's okay if you want to do it!

  5. added 2 commits that reference this issue on Aug 28, 2025
    88285f7
    1f70e88
  6. Huiyeongkim commented on Aug 29, 2025

    @Huiyeongkim

    @chanhyeong
    Thank you for giving me the opportunity! I really appreciate it.

  7. sharanggupta commented on Oct 22, 2026

    @sharanggupta

    @schauder, I have a branch covering this together with #2417, offered on #2418; happy to split the id-column part out into its own PR if you prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions