Skip to content

Hibernate 7: support DB2 in the unique key null handling, and test it #16746

Open

Description

@borinquenkid

Problem

The code that chooses how a unique key is built or read for a nullable key treats DB2 like H2, PostgreSQL, MySQL, MariaDB and SQL Server: a row with a null in the key never conflicts. That is not verified for DB2 and may be wrong.

Hibernate creates DB2's unique key as create unique index ... exclude null keys (DB2Dialect#getCreateIndexTail; AlterTableUniqueIndexDelegate says DB2 does not allow unique constraints on nullable columns). As far as I know, exclude null keys leaves out an entry only when all of its key columns are null, and DB2 compares the other nulls as equal, so ('en', null) twice would conflict, as on Oracle. Nobody has run this on DB2.

Where the assumption is made

What is needed

  1. A DB2 container spec (Testcontainers db2 module, icr.io/db2_community/db2) added to the database matrix of SharedJoinTableHibernate7Spec, SharedKeyColumnHibernate7Spec and UniqueNullsHibernate7Spec, so the behavior is measured and not read from the source.
  2. If DB2 compares partly null keys, give it the COMPARED / value reading, with the DDL in SharedJoinTableUniqueKeyBinderSpec adjusted, and correct the documentation tables.
  3. Say in the documentation which databases the tests cover.

The unit-level DDL specs only show the DDL Hibernate renders. They do not show how DB2 treats the index.

Activity

  1. borinquenkid commented on Oct 24, 2026

    @borinquenkid
    MemberAuthor

    Fixed by #16750 (Hibernate 7: unique key nulls, regular expressions and native SQL reading on Db2 LUW, IBM i and z/OS, with Db2 container rows on CI), with #16751 (Hibernate 5: rlike on Db2) and the Db2 readings of the unique constraint in #16583 (9.0.x).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions