spring-projects / spring-data-relational

Spring Data Relational. Home of Spring Data JDBC and Spring Data R2DBC.
https://spring.io/projects/spring-data-jdbc
Apache License 2.0
753 stars 345 forks source link

JdbcTemplate incorrectly generates an sql request #1722

Closed bifrurcated closed 7 months ago

bifrurcated commented 7 months ago

I have a project using jdbc and postgres. I have a schema.sql where the "usr" and "token" tables are created. The token table has the relationship "CONSTRAINT fk_token_user FOREIGN KEY ("user") PREFERENCES usr (id)". I switched from Spring Boot 2.7.5 to 3.1.2. When I make a findByEmail request, I get the error: org.postgresql.util.PSQLException: ERROR: the token.usr column does not exist Hint: Perhaps a reference to the "token.user" column was intended. Position: 142 I have enabled the debug logs and different requests are being received: Spring Boot 2.7.5: [SELECT "token"."issue_at" AS "issue_at", "token"."expired_at" AS "expired_at", "token"."refresh_token" AS "refresh_token" FROM "token" WHERE "token"."user" = ?] Spring Boot 3.1.2: [SELECT "token"."issue_at" AS "issue_at", "token"."expired_at" AS "expired_at", "token"."refresh_token" AS "refresh_token" FROM "token" WHERE "token"."usr" = ?]

mp911de commented 7 months ago

If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal yet complete sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

bifrurcated commented 7 months ago

twoDemoProjects.zip Here are two perfectly identical projects, there is a test on version 2.7.5, it passes on new versions (3.1.2, 3.2.2), it does not pass

bifrurcated commented 7 months ago

It was necessary to create a foreign key with the same name as the table. Apparently, in the old version, it was specified by the name of the class and did not take into account the @Table(name) annotation