【问题标题】:Incorrect syntax near the keyword 'key'关键字“key”附近的语法不正确
【发布时间】:2020-05-30 12:56:30
【问题描述】:

我正在尝试将一个新对象持久化到数据库中,但出现此错误:

SQL 错误:156,SQLState:S0001

关键字“key”附近的语法不正确。

我在做什么

Bucket bucket = new Bucket();
bucket.setKey(key);
bucket.setValue(value);


entityManager.persist(bucket);

我相信这个错误是由于在 sql 语句中使用了关键字“key”导致的。是否有可用于在表中插入行的本机查询?

我的表有这三列,ID 是自动生成的。

桶:

@Entity
@Getter
@Setter
@ToString
public class Bucket {

    @Id @GeneratedValue(strategy= GenerationType.IDENTITY)
    private long id; //auto allocation of PK
    private String key;
    private String value;
} 

【问题讨论】:

标签: java spring-boot jpa


【解决方案1】:

感谢马丁·史密斯的帮助。只需一个简单的更改,问题就解决了。

桶:

@Entity
@Getter
@Setter
@ToString
public class Bucket {

    @Id @GeneratedValue(strategy= GenerationType.IDENTITY)
    private long id; //auto allocation of PK
    @Column(name = "\"key\"")
    private String key;
    @Column(name = "\"value\"")
    private String value;
} 

【讨论】:

    猜你喜欢
    • 2016-06-08
    • 2013-12-16
    • 2017-11-22
    • 2018-06-16
    • 2013-10-29
    • 2014-06-22
    • 1970-01-01
    • 2013-05-04
    • 2013-05-21
    相关资源
    最近更新 更多