Use force-quoting in `R2dbcMappingContext` by default
I have a table where the field is desc. Since it's a reserved keyword in PostgreSQL, I had to use the annotation @Column("\"desc\"") to allow it to be written properly. However, when reading the data, I found that it cannot be read correctly because in org.springframework.data.relational.core.conversion.MappingRelationalConverter#read, the org.springframework.data.relational.core.conversion.RowDocumentAccessor#hasValue method doesn't recognize the field. I believe some logic should be added here to solve this issue.
can we add a annotation like @ResultSetKey("desc") or other way to support it @mp911de @schauder
With @Column("\"desc\"") you make the double quotes part of the column name. Is that intended? SQL identifier in @Column, @Table and similar annotations are used exactly as they are given, and properly quoted to avoid interpretation as key words, or automatic changes to upper or lower case.
Therefore I guess you really want to use @Column("desc").
If that still doesn't work, please provide a full reproducer, preferably base on https://github.com/schauder/issue-jdbc-1993
@schauder Thank you for your help, and sorry I forgot to mention that this bug occurs under r2dbc. I tried using the demo provided in your repository for testing, but I’m not sure how to use TestcontainersConfiguration. I believe when using r2dbc, saving data causes an error. The logs I printed indicate that it is not treating field and table names as keywords.
The cause of the bug seems to be that the default values provided by org.springframework.data.r2dbc.mapping.R2dbcMappingContext are inconsistent with JDBC. Should I submit a PR to fix this issue?
public R2dbcMappingContext(NamingStrategy namingStrategy) {
super(namingStrategy);
// use setForceQuote(true) to support keyword fields
setForceQuote(false);
}
We initially didn't want to enable forceQuote for R2DBC to retain compatibility. It would make sense to align for the next major revision, so feel free to submit a pull request. I assume that updating all tests will be the major effort here.
@mp911de @schauder After changing the default values and modifying some test cases, I found that besides the changes to the default values, places like DefaultStatementMapper, UpdateMapper, and QueryMapper are all using SqlIdentifier.unquoted(xxx) by default. This might mean that more changes are required to fully meet our expectations.
have any other feedback?@mp911de
I looked at a couple of these cases, and those looked fine to me.
If you have any special cases in mind that seem suspicious to you let me know.
As part of the review I'll take a look at the unquoted calls within R2DBC and check if I think there are further things to change.
Sorry for the delayed response to this issue. Below is my personal repository where I made temporary changes: https://github.com/ShenFeng312/spring-data-relational. I have also fixed some test cases. When I realized how many changes were required to support this, I started to feel that my approach might be flawed. Given that I don't fully understand the design, I felt that I shouldn't make such extensive modifications without fully understanding it. I hope the community can support this feature soon. Thank you very much. @schauder
Could you make a PR anyway? This way this doesn't get lost, which it very likely will when it just sits here as a comment.