Search code examples
javadatabasespring-bootliquibase-hibernateliquibase-maven-plugin

Liquibase with Hibernate drop and add foreign key contraint every time. Why?


I'm using Liquibase maven plugin. There are some entity in my spring-boot application and I used the command mvn liquibase:diff with the DB empty. So the generated changelog represent the initial DB structure.

This first step works well, when I start my application, Liquibase execute this generated changelog and create all the tables, contraint, sequence.

But after the creation of DB, if I execute again the command mvn liquibase:diff, I expect the new generated changelog to be empty. Instead, every time I run the command mvn liquibase:diff Liquibase create these changeset.

- changeSet:
    id: 1709542912189-1
    author: MarcelloVestri (generated)
    changes:
    - dropForeignKeyConstraint:
        baseTableName: patient
        constraintName: FK_PAT_DOC
- changeSet:
    id: 1709542912189-2
    author: MarcelloVestri (generated)
    changes:
    - addForeignKeyConstraint:
        baseColumnNames: PAT_DOC_ID
        baseTableName: patient
        constraintName: FK_PAT_DOC
        referencedColumnNames: DOC_ID
        referencedTableName: doctor

I think that is a Hibernate routine drop and recreate the foreign key. I searched on internet but I haven't found anything about why this happens.

Is there any property of Hibernate to make it not have this behavior?


Solution

  • this is the same behavior as https://github.com/liquibase/liquibase-hibernate/issues/436 .