Skip to content

RowDocumentResultSetExtractor : ResultSet contains column "id" multiple times #2045

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

Open
fsudau opened this issue Apr 25, 2025 · 0 comments
Open
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@fsudau
Copy link

fsudau commented Apr 25, 2025

Affects version 3.4.5

Hi,

I am experiencing this issue where the line RowDocumentResultSetExtractor : ResultSet contains column "id" multiple times. Later column index is 2 is logged on WARN every time I execute a (generated) statement. This could either be a bug or entirely my fault. In any case, I investigated this quiet a bit and could not fix it, so here we go:

I am using Postgres and created these 2 tables (forming a simple aggregate) using quotes and in all-lowercase. Thus, the identifiers are indeed stored as lower case in the db schema:

CREATE TABLE "users"
(
    "id"   UUID DEFAULT gen_random_uuid() PRIMARY KEY,
    "name" TEXT NOT NULL
);

CREATE TABLE "user_items"
(
    "id"       UUID PRIMARY KEY,
    "code"     TEXT NOT NULL,
    "users_fk" UUID REFERENCES "users"
);

My "entities" are defined as follows:

@Table("user_items")
public class UserItem {

    @Id
    private UUID id;
    private String code;
}

@Table("users")
public class User {

    @Id
    private UUID id;
    private String name;
    @MappedCollection(idColumn = "users_fk", keyColumn = "id")
    private List<UserItem> items;

}

Queries on the User aggregate without any custom SQL, for example userRepository.findAll(), will then produce the warning mentioned above. Example project here.

Some Background

  • The Postgres dialect is detected correctly.
  • Fiddling around with NamingStrategy does not impact this; the NamingStrategy is applied later in the process.
  • Capitalizing keyColumn will break the application entirely.

It seems to me that the fix from #1073 does not work here due to the odd setup in terms of casing. Although everything I wrote is in lower case, there is still some mixup happening. The problem is already apparent in SqlGenerator#selectBuilder(Collection<SqlIdentifier> keyColumns).
The key column name from my annotation is passed as a DefaultSqlIdentifier and the columns inferred from the field names as DerivedSqlIdentifier. DerivedSqlIdentifier then capitalizes the column name in toSql(IdentifierProcessing processing) although I am running a Postgres and DefaultSqlIdentifier does not capitalize.
The set logic in SqlGenerator will then not de-dupe these columns with different casing and in the end a query of the form SELECT "user_items"."id" AS "id", "user_items"."code" AS "code", "user_items"."id" AS "id" FROM "user_items" WHERE "user_items"."users_fk" = ('df07723f-6e8b-425c-a888-90c13c399799'::uuid) ORDER BY "id" is generated.
The sql "works" fine of course, making this a minor issue.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants