Skip to content

mysql keyword isn't mapping to the result #861

@maple-seven

Description

@maple-seven
@Getter
@Setter
@Table("table")
public class SpotMarginUserSettingEntity {

    @Id
    private Long id;
    @Column("uid")
    private Long uid;
    @Column("`key`")
    private String key;
    @Column("value")
    private String value;
    @Column("created_at")
    private Instant createdAt;

}

The field key return null when query , if set the @column("key") it works fine ; but it'll error when insert or update because key is a keyword in mysql;

Activity

changed the title [-]mysql keyword is't mapping to the result[/-] [+]mysql keyword isn't mapping to the result[/+] on Jun 20, 2024
mp911de

mp911de commented on Jun 20, 2024

@mp911de
Member

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.

maple-seven

maple-seven commented on Jun 21, 2024

@maple-seven
Author

java

@Getter
@Setter
@Table("demo")
public class Demo {
    @Id
    private Long id;
    @Column("uid")
    private Long uid;
    @Column("`key`")
    private String key;
    @Column("value")
    private String value;
    @Column("created_at")
    private Instant createdAt;
}

sql:

create table demo
(
    id         int unsigned auto_increment
        primary key,
    uid        bigint(11) unsigned default 0                 not null comment '',
    `key`      varchar(100)        default ''                not null comment '',
    value      varchar(100)        default ''                not null comment '',
    created_at datetime            default CURRENT_TIMESTAMP not null
);

INSERT INTO demo (uid, `key`, value) VALUES (10000, 'key1', '0');

query:

public interface SpotMarginUserSettingReadRepository extends R2dbcRepository<Demo, Long> {

    @Query("select * from demo where `key`= 'key1' and uid = :uid limit 1")
    Mono<Demo> getSomeDemo(long uid);
}

the field key in result is null;
if i remove backtick in @column("`key`") it works fine;
but when it excutes insert or update, it will throw a bad sql error;

mp911de

mp911de commented on Jun 21, 2024

@mp911de
Member

R2dbcMappingContext doesn't quote identifiers by default. Can you retest when setting R2dbcMappingContext.setForceQuote(true)? I think you will have to register a custom R2dbcMappingContext bean.

spring-projects-issues

spring-projects-issues commented on Aug 19, 2024

@spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues

spring-projects-issues commented on Aug 26, 2024

@spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mp911de@spring-projects-issues@maple-seven

        Issue actions

          mysql keyword isn't mapping to the result · Issue #861 · spring-projects/spring-data-r2dbc