Skip to content

Use force-quoting in R2dbcMappingContext by default #1993

Open
@ShenFeng312

Description

@ShenFeng312

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.

Activity

changed the title [-]MappingR2dbcConverter cannot convert reserved keyword fields[/-] [+]MappingRelationalConverter cannot convert reserved keyword fields[/+] on Feb 14, 2025
ShenFeng312

ShenFeng312 commented on Feb 17, 2025

@ShenFeng312
Author

can we add a annotation like @ResultSetKey("desc") or other way to support it @mp911de @schauder

schauder

schauder commented on Feb 17, 2025

@schauder
Contributor

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

ShenFeng312

ShenFeng312 commented on Feb 18, 2025

@ShenFeng312
Author

@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.

ShenFeng312

ShenFeng312 commented on Feb 18, 2025

@ShenFeng312
Author

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);
	}
mp911de

mp911de commented on Feb 18, 2025

@mp911de
Member

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.

changed the title [-]MappingRelationalConverter cannot convert reserved keyword fields[/-] [+]Use force-quoting in `R2dbcMappingContext` by default[/+] on Feb 18, 2025

10 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @schauder@mp911de@spring-projects-issues@ShenFeng312

    Issue actions

      Use force-quoting in `R2dbcMappingContext` by default · Issue #1993 · spring-projects/spring-data-relational