Java 将Spring boot升级到2.3.0时出现Spring数据问题

Java 将Spring boot升级到2.3.0时出现Spring数据问题,java,spring-boot,spring-data-jdbc,Java,Spring Boot,Spring Data Jdbc,该项目目前处于spring boot 2.27(以及相应的spring data jdbc版本)上,在maven中升级版本并运行时,我收到以下消息: bad SQL grammar [INSERT INTO "PLAYLIST" ("allocated_funds", "file_uri", "received") VALUES (?, ?, ?)]; nested exception is org.postgresql.util.PSQLException: ERROR: relation "

该项目目前处于spring boot 2.27(以及相应的spring data jdbc版本)上,在maven中升级版本并运行时,我收到以下消息:

bad SQL grammar [INSERT INTO "PLAYLIST" ("allocated_funds", "file_uri", "received") VALUES (?, ?, ?)]; nested exception is org.postgresql.util.PSQLException: ERROR: relation "PLAYLIST" does not exist

org.springframework.data.relational.core.conversion.DbActionExecutionException: Failed to execute DbAction.InsertRoot(entity=Playlist(id=null, fileUri=gs://playlists/success.csv, received=2020-05-26T09:34:45.778327, allocatedFunds=20000))
我正在使用flyway管理我的db,测试正在执行:

09:34:43.868 [main] INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
09:34:43.897 [main] INFO  o.f.c.i.database.DatabaseFactory - Database: jdbc:postgresql://localhost:32883/test (PostgreSQL 12.3)
09:34:43.947 [main] INFO  o.f.core.internal.command.DbValidate - Successfully validated 4 migrations (execution time 00:00.019s)
09:34:43.970 [main] INFO  o.f.c.i.s.JdbcTableSchemaHistory - Creating Schema History table "public"."flyway_schema_history" ...
09:34:44.010 [main] INFO  o.f.core.internal.command.DbMigrate - Current version of schema "public": << Empty Schema >>
INFO  o.f.core.internal.command.DbMigrate - Migrating schema "public" to version 1 - init
INFO  o.f.core.internal.command.DbMigrate - Migrating schema "public" to version 2 - playlist entry
INFO  o.f.core.internal.command.DbMigrate - Migrating schema "public" to version 3 - splits
INFO  o.f.core.internal.command.DbMigrate - Migrating schema "public" to version 4 - allocated funds
INFO  o.f.core.internal.command.DbMigrate - Successfully applied 4 migrations to schema "public" (execution time 00:00.255s)
创建脚本如下所示:

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;

@Data
@Builder
@AllArgsConstructor
@Table("PLAYLIST")
public class Playlist implements Serializable {
    @Id
    private Long id;

    @Column("file_uri")
    private String fileUri;

    private LocalDateTime received;

    @Column("allocated_funds")
    private BigDecimal allocatedFunds;
}
CREATE TABLE PLAYLIST(id BIGSERIAL PRIMARY KEY, file_uri VARCHAR(400) NOT NULL, received TIMESTAMP NOT NULL);
ALTER TABLE PLAYLIST ADD COLUMN allocated_funds DECIMAL(10,2) NOT NULL;
WRT datetime或bigdecimal处理或缺少ID是否存在一些潜在的更改

  • 更新-添加存储库代码

导入org.springframework.data.jdbc.repository.query.query;
导入org.springframework.data.repository.crudepository;
导入org.springframework.data.repository.query.Param;
导入treeline.entities.Playlist;
公共接口播放库扩展了Crudepository{
@查询(“从播放列表p中选择*,其中p.file_uri=:fileUri”)
播放列表findByFileUri(@Param(“fileUri”)最终字符串fileUri);
}
看起来像

INSERT INTO "PLAYLIST"
这就是问题所在。你能试试不加引号吗?只需按如下方式编写查询

INSERT INTO PLAYLIST
看起来像

INSERT INTO "PLAYLIST"
这就是问题所在。你能试试不加引号吗?只需按如下方式编写查询

INSERT INTO PLAYLIST

引用的对象名称区分大小写,因此可能有一个表
播放列表
(小写),但插入的是不存在的
播放列表
。禁用引号,或尝试删除
@Table
注释,或将该表放在小写形式。表播放列表的create语句按提供的大写形式显示是,但不带引号,且不带引号的对象名称不区分大小写,这意味着PostgreSQL将以小写形式存储它(例如,其他数据库系统将不带引号的名称存储为大写)。这意味着
播放列表
实际上是
播放列表
,并且
“播放列表”
将不匹配。在
@表
中更改为小写,并对其进行了排序。带引号的对象名称区分大小写,因此您可能有一个表
播放列表
(小写),但您正在插入不存在的
播放列表
。请禁用引号,或尝试删除
@Table
注释,或将该表放在小写字母中。表播放列表的create语句与提供的一样是大写字母,但在那里它是不带引号的,且不带引号的对象名称不区分大小写,这意味着PostgreSQL将以小写形式存储它(例如,其他数据库系统将不带引号的名称存储为大写)。这意味着
PLAYLIST
实际上是
PLAYLIST
,而
“PLAYLIST”
将不匹配。在
@Table
中更改为小写,并对其进行排序。spring data Crudepository正在生成查询。-添加用于保存的存储库代码粘贴了select查询而不是insert。总之,查询由您控制。我建议您从查询中删除引号。
保存
功能City是Crudepository的一部分。我只是展示了我对该实体的了解。我已经解决了问题。更改了表名以降低大小写spring data Crudepository正在生成查询。-添加了用于保存的存储库代码。您粘贴了选择查询,而不是插入。总之,查询由您控制。我建议您删除t他引用了查询中的内容。
save
功能是crudepository的一部分。我只是展示了我对该实体的了解。我已经解决了问题,将表名改为小写