【发布时间】:2020-05-15 11:49:19
【问题描述】:
我有一个 Spring Boot 应用程序,我想创建带有实体注释的表。当我运行 jar 时,如果表已经存在,应用程序会在没有警告的情况下启动。 但是如果数据库是空的,那么我会为每个表收到这些警告:
GenerationTarget encountered exception accepting command : Error executing DDL "alter table mytable drop constraint if exists FKk53mrkxu32slsax6fmn164ijy" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table mytable drop constraint if exists FKk53mrkxu32slsax6fmn164ijy" via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:375) ~[hibernate-core-5.3.7.Final.jar!/:5.3.7.Final] (....)
还有:
2020-05-15 11:23:24.998 WARN 20319 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 0, SQLState: 00000
2020-05-15 11:23:24.998 WARN 20319 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : table "mytable" does not exist, skipping
即使出现这些警告,应用程序也能正常工作,那么有没有办法解决问题或抑制警告?
我的 application.properties 数据库相关行:
spring.datasource.url=jdbc:postgresql://localhost:5432/mydatabase
spring.datasource.username=user
spring.datasource.password=user
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.initialize=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
更新: 第一个较长的异常仅在表具有外键并且异常的结尾如下所示时发生:
Caused by: org.postgresql.util.PSQLException: ERROR: relation "mytable" does not exist
或
Caused by: org.postgresql.util.PSQLException: ERROR: relation "student_x_course" does not exist
出现异常后,Hibernate 运行 CREATE TABLE ... sql 语句。
【问题讨论】:
标签: java hibernate spring-boot jpa