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

时间:2020-05-26 07:41:58

标签: 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 "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管理我的数据库,该数据库正在由测试执行:

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日期时间是否存在一些根本性的变化,或者是十进制处理还是缺少ID?

  • 更新-添加存储库代码

import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import treeline.entities.Playlist;

public interface PlaylistRepository extends CrudRepository<Playlist, Long> {
    @Query("SELECT * FROM Playlist p WHERE p.file_uri = :fileUri")
    Playlist findByFileUri(@Param("fileUri") final String fileUri);
}

1 个答案:

答案 0 :(得分:0)

看起来像

INSERT INTO "PLAYLIST"

是问题所在。您可以尝试不使用引号吗?只需编写如下查询

INSERT INTO PLAYLIST