Skip to content

Bug encountered with duplicate column names in result set, but only in specific alias order  #1680

Closed
@edwardmp

Description

@edwardmp

Hey folks,

Noticed a weird bug today.

Suppose I have the following entity structure:

CREATE TABLE "group" (
    uuid UUID PRIMARY KEY,
    name TEXT NOT NULL
);

CREATE TABLE "user" (
    uuid UUID PRIMARY KEY,
    name TEXT NOT NULL,
    group_uuid UUID,
    FOREIGN KEY (group_uuid) REFERENCES "group" (uuid)
);

E.g. a root entity group and embedded entity user.

Before I had a query like this, which worked fine using Spring data JDBC 2.4.16 despite the duplicate column name in both entities.
There was something logged though ResultSet contains name multiple times, but in my case everything worked fine.
I remember this from the past, because back then I could not find a proper fix that would remove the warning, however it seemed harmless at the time.

I recently upgraded to Spring Data JDBC 3.2.0 and this behavior has now changed.
There is nothing logged, and the value of the name columns is swapped between the entities, e.g. the group entity will have the name of the user, and the user will have the name of the group.

Anyhow, I guess it's logical that due to the single select * Spring Data JDBC couldn't figure it out, not sure why the warning message no longer is logged though.
I found #1073 which might explain this change, and based on this I modified my query to:

@Query(
    """
        select u.*, g.*
        from group g
        inner join user u on u.group_uuid = g.uuid
    """,
)
fun findAll(
): List<Group>

Then, everything works as expected.

However I also noticed that if I swap the order of select aliases, the issue appears again:

@Query(
    """
        select g.*, u.*
        from group g
        inner join user u on u.group_uuid = g.uuid
    """,
)
fun findAll(
): List<Group>

So I have 2 questions/remarks:

  1. Why is there nothing logged anymore like before if Spring Data JDBC can't figure out the column mapping due to duplicate names like before? This would have saved me quite some debugging time.
  2. Why does Spring Data JDBC still swap the values across entities with the correct query syntax if the order is different? I can't think of any valid reason why the order should matter here.

@schauder perhaps you have an idea here since you worked on the related commit.

Edit: I had to downgrade to Spring Boot 3.1.5 (and thus Spring Data JDBC 3.1.5) for other reasons, and now I notice that the issue is inverted again.

E.g. this works:

@Query(
    """
        select g.*, u.*
        from group g
        inner join user u on u.group_uuid = g.uuid
    """,
)
fun findAll(
): List<Group>

But swapping g.* and u.* makes it fail here. So exactly inverted of what happens with 3.2.0.. very puzzling

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions