Hibernate H2 specify drop table order

后端 未结 2 1278
天涯浪人
天涯浪人 2021-01-06 02:42

I have pretty much the same problem like this user. Hibernate can\'t drop the tables of my in-memory test database after each SpringBootTest (e.g. when running mvn test). Th

2条回答
  •  滥情空心
    2021-01-06 03:38

    I finally found a work around for my problem. As I said, the errors where caused by trying to drop tables on which other tables still depend on. I thought that this could be related to missing CascadeType specifcations, but I couldn't fix it.

    Then I found this answer and it works for me. Additional to my data.sql file (where all my data is inserted to the auto-created schema) I now have a drop-tables.sql where I can specify the correct order of DROP statements. This file is executed before the automatic schema creation and therefore solves my problem.

    application.properties:

    spring.jpa.properties.javax.persistence.schema-generation.database.action=drop-and-create
    spring.jpa.properties.javax.persistence.schema-generation.drop-source=script-then-metadata
    spring.jpa.properties.javax.persistence.schema-generation.drop-script-source=drop-tables.sql
    

提交回复
热议问题