spring-data-relational icon indicating copy to clipboard operation
spring-data-relational copied to clipboard

JdbcTemplate incorrectly generates an sql request

Open bifrurcated opened this issue 2 years ago • 3 comments

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" = ?]

bifrurcated avatar Jan 22 '24 20:01 bifrurcated

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.

mp911de avatar Jan 23 '24 07:01 mp911de

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 avatar Jan 23 '24 09:01 bifrurcated

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

bifrurcated avatar Feb 09 '24 16:02 bifrurcated