Quarkus Hibernate ORM-port.sql未执行

n3schb8v  于 2022-11-14  发布在  其他
关注(0)|答案(2)|浏览(166)

出于测试目的,我使用Quarkus DevServices启动Postgres数据库。
正如在https://quarkus.io/blog/hibernate-orm-config-profiles/中提到的,我将生成设置为drop-and-create,并创建了必须在每次启动应用程序时从头开始创建数据库表的port.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仍然会被执行,而port.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;
gojuced7

gojuced71#

请参阅https://quarkus.io/guides/hibernate-orm#quarkus-hibernate-orm_quarkus.hibernate-orm.scripts-database-scripts-related-configuration上的指南
属性“Quarkus.hibernate-orm.SQL-Load-SCRIPT”用于加载数据(主要是INSERT语句)。
对于DDL(创建和删除表),您可能必须使用以下属性:

quarkus.hibernate-orm.scripts.generation=drop-and-create
quarkus.hibernate-orm.scripts.generation.create-target=create.sql
quarkus.hibernate-orm.scripts.generation.drop-target=drop.sq
nhhxz33t

nhhxz33t2#

当发生模式更改(如创建新表)时,将调用port.sql。因此,它仅在您将数据库生成更改为DROP-AND-CREATE时运行。

quarkus.hibernate-orm.scripts.generation=drop-and-create

初始化数据库后,您可以将数据库生成设置改回更新

quarkus.hibernate-orm.scripts.generation=update

相关问题