Skip to content

Flyway "Generate Migration File" produces incorrect DDL for @NaturalId #53551

@mhagnumdw

Description

@mhagnumdw

Describe the bug

If an attribute is annotated with @NaturalId, Hibernate automatically generates a unique constraint.

The "Generate Migration File" option in Dev UI > Extensions > Flyway reports a diff that does not exist, for example:

    alter table jarvis.DEMANDA 
       drop constraint UKm5w2uipg0ovfi452ah22gkibr;

    alter table jarvis.DEMANDA 
       add constraint UKm5w2uipg0ovfi452ah22gkibr unique (IDENTIFICADOR);

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

Create an entity like this:

@Entity
@Table(name = "DEMANDA")
public class Demanda {

    @NaturalId
    @Column(name = "IDENTIFICADOR", nullable = false, updatable = false, length = 50)
    private String identificador;
}

Create the corresponding migration file.

Generate the migration file via Dev UI.

Output of uname -a or ver

Linux dwnote2 6.19.10-200.fc43.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Mar 25 16:09:19 UTC 2026 x86_64 GNU/Linux

Output of java -version

openjdk version "21.0.9" 2025-10-21 LTS OpenJDK Runtime Environment Temurin-21.0.9+10 (build 21.0.9+10-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.9+10 (build 21.0.9+10-LTS, mixed mode, sharing)

Quarkus version or git rev

3.31.4

Build tool (ie. output of mvnw --version or gradlew --version)

3.9.12

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions