Skip to content

@NotNull does not add not null to persistence unit #46034

@LarsSven

Description

@LarsSven

Describe the bug

With Hibernate ORM, we have an entity that has a @NotNull annotation. According to documentation, Hibernate should pick this up and add not null to the column in the Persistent Unit. However, when you do that on Quarkus 3.18.1, not null is not added to the persistence unit.

This used to be properly applied, until at some point we discovered after a few Quarkus updates that this suddenly no longer happens, so I am not sure in which version this stopped working.

I made a small reproducer at https://gitlab.com/l.s.andringa1/quarkus-hibernate-non-null-reproducer

The project is in Kotlin since that is what we are used to. I am not sure whether it only happens on Kotlin or also on Java. I tried to put both kotlin and java entities in the same project to test, but it was not added to the same persistence unit.

Expected behavior

When @NotNull is added to an entity, as follows:

@Entity
class MyKotlinEntity {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    var id: Long? = null

    @NotNull
    var field: String = ""
}

The persistence unit (for MariaDB in this case) should look like:

create table MyKotlinEntity (
    id bigint not null auto_increment,
    field varchar(255) not null,
    primary key (id)
) engine=InnoDB;

Actual behavior

When @NotNull is added to an entity, as follows:

@Entity
class MyKotlinEntity {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    var id: Long? = null

    @NotNull
    var field: String = ""
}

The persistence unit looks as follows:

create table MyKotlinEntity (
    id bigint not null auto_increment,
    field varchar(255),
    primary key (id)
) engine=InnoDB;

How to Reproduce?

Reproducer:

  1. Clone https://gitlab.com/l.s.andringa1/quarkus-hibernate-non-null-reproducer
  2. Open Quarkus dev dashboard and look at Hibernate ORM persistence unit
  3. Observe the Create Script, which is missing the not null annotation for the field

Output of uname -a or ver

Windows 11 (Also tested on Ubuntu 24.10)

Output of java -version

OpenJDK Runtime Environment Corretto-21.0.5.11.1

Quarkus version or git rev

3.18.1

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

Gradle 8.12.1

Additional information

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions