【发布时间】:2022-09-29 07:05:37
【问题描述】:
我使用 Quarkus Devservices 来启动 postgres db 以进行测试。
正如https://quarkus.io/blog/hibernate-orm-config-profiles/ 中提到的那样,我将生成设置为drop-and-create 并创建了 import.sql 文件,每次启动应用程序时都必须使用该文件从头开始创建数据库表,但是没有创建任何内容,而是收到奇怪的错误消息不适合 postgres 数据库的状态。
2022-03-12 13:43:29,851 WARN [org.hib.eng.jdb.spi.SqlExceptionHelper] (JPA Startup Thread: <default>) SQL Warning Code: 0, SQLState: 00000
2022-03-12 13:43:29,852 WARN [org.hib.eng.jdb.spi.SqlExceptionHelper] (JPA Startup Thread: <default>) relation \"filepart\" does not exist, skipping
2022-03-12 13:43:29,853 WARN [org.hib.eng.jdb.spi.SqlExceptionHelper] (JPA Startup Thread: <default>) SQL Warning Code: 0, SQLState: 00000
2022-03-12 13:43:29,854 WARN [org.hib.eng.jdb.spi.SqlExceptionHelper] (JPA Startup Thread: <default>) table \"download\" does not exist, skipping
2022-03-12 13:43:29,855 WARN [org.hib.eng.jdb.spi.SqlExceptionHelper] (JPA Startup Thread: <default>) SQL Warning Code: 0, SQLState: 00000
2022-03-12 13:43:29,855 WARN [org.hib.eng.jdb.spi.SqlExceptionHelper] (JPA Startup Thread: <default>) table \"filepart\" does not exist, skipping
2022-03-12 13:43:29,867 WARN [org.hib.eng.jdb.spi.SqlExceptionHelper] (JPA Startup Thread: <default>) SQL Warning Code: 0, SQLState: 42P07
2022-03-12 13:43:29,867 WARN [org.hib.eng.jdb.spi.SqlExceptionHelper] (JPA Startup Thread: <default>) relation \"download\" already exists, skipping
2022-03-12 13:43:29,868 WARN [org.hib.eng.jdb.spi.SqlExceptionHelper] (JPA Startup Thread: <default>) SQL Warning Code: 0, SQLState: 42P07
2022-03-12 13:43:29,868 WARN [org.hib.eng.jdb.spi.SqlExceptionHelper] (JPA Startup Thread: <default>) relation \"filepart\" already exists, skipping
2022-03-12 13:43:51,035 INFO [io.quarkus] (Quarkus Main Thread) quarkus-resteasy-postgres 1.0.0-SNAPSHOT on JVM (powered by Quarkus 2.7.4.Final) started in 27.125s. Listening on: http://localhost:8080
应用程序属性:
quarkus.datasource.devservices.enabled=true
quarkus.datasource.db-kind=postgresql
quarkus.datasource.devservices.port=5432
quarkus.datasource.username=postgres
quarkus.datasource.password=postgres
quarkus.hibernate-orm.database.generation=drop-and-create
# it is default, only explicit to be clear:
quarkus.hibernate-orm.sql-load-script=import.sql
完整的项目在这里: https://github.com/syr/quarkus-resteasy-postgres/tree/hibernate_drop_not_working
更新:当禁用数据库生成时
quarkus.hibernate-orm.database.generation=none
显然是从实体生成的 SQL 仍然被执行,而 import.sql 被忽略。
create table Download (idProperty1 varchar(255) not null, idProperty2 varchar(255) not null, finished boolean, id int8, primary key (idProperty1, idProperty2));
create table FilePart (id int8 not null, filePartFilePath varchar(255), idProperty1 varchar(255), idProperty2 varchar(255), primary key (id));
alter table if exists FilePart add constraint FKia6okjgd7yxo21sfga0hej3ni foreign key (idProperty1, idProperty2) references Download;
标签: postgresql hibernate quarkus quarkus-panache