收到一系列 SQL 警告:“关系 <表> 不存在,正在跳过”

dis*_*ame 8 postgresql spring hibernate spring-boot

我不知道这是否值得担心,但当服务器启动时,我收到一系列警告:

o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Warning Code: 0, SQLState: 00000
o.h.engine.jdbc.spi.SqlExceptionHelper   : relation "app_user__user_group" does not exist, skipping
o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Warning Code: 0, SQLState: 00000
o.h.engine.jdbc.spi.SqlExceptionHelper   : relation "app_user__user_group" does not exist, skipping
o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Warning Code: 0, SQLState: 00000
o.h.engine.jdbc.spi.SqlExceptionHelper   : relation "google_place" does not exist, skipping
o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Warning Code: 0, SQLState: 00000
 ...
Run Code Online (Sandbox Code Playgroud)

我不能说这引起了问题 - 到目前为止一切正常 - 但我想了解这里发生了什么。

这是我正在使用的配置:

o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Warning Code: 0, SQLState: 00000
o.h.engine.jdbc.spi.SqlExceptionHelper   : relation "app_user__user_group" does not exist, skipping
o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Warning Code: 0, SQLState: 00000
o.h.engine.jdbc.spi.SqlExceptionHelper   : relation "app_user__user_group" does not exist, skipping
o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Warning Code: 0, SQLState: 00000
o.h.engine.jdbc.spi.SqlExceptionHelper   : relation "google_place" does not exist, skipping
o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Warning Code: 0, SQLState: 00000
 ...
Run Code Online (Sandbox Code Playgroud)

作为示例,这里是@Entityfor google_place

@Entity
@Table(name = "google_place")
public class GooglePlace extends AbstractTimestampEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @OneToOne
    @JoinColumn(name = "place_id")
    private Place place;

    @Column(name = "google_place_id", unique = true)
    private String googlePlaceId;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Place getPlace() {
        return place;
    }

    public void setPlace(Place place) {
        this.place = place;
    }

    public String getGooglePlaceId() {
        return googlePlaceId;
    }

    public void setGooglePlaceId(String googlePlaceId) {
        this.googlePlaceId = googlePlaceId;
    }

}
Run Code Online (Sandbox Code Playgroud)

小智 7

当数据库尝试删除较旧的对象时会发生此错误。您可以使用 来检查它发生的确切时刻spring.jpa.show-sql=true,但是,如果您进行更改,spring.jpa.hibernate.ddl-auto=createcreate-drop不是您将不再看到这些警告,因为它不会尝试删除不存在的对象。

来自Hibernate 文档

create创建数据库后将生成数据库删除。

create-drop删除架构并在 SessionFactory 启动时重新创建它。此外,在 SessionFactory 关闭时删除架构。