openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Heath Thomann (JIRA)" <>
Subject [jira] [Resolved] (OPENJPA-1387) Unique colums automatically defined as non-nullable
Date Wed, 23 Jan 2013 23:43:12 GMT


Heath Thomann resolved OPENJPA-1387.

    Resolution: Fixed
> Unique colums automatically defined as non-nullable
> ---------------------------------------------------
>                 Key: OPENJPA-1387
>                 URL:
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: sql
>    Affects Versions: 1.2.3, 2.0.0-M3
>         Environment: Error happens in every environment.
>            Reporter: Martin Dirichs
>            Assignee: Heath Thomann
>             Fix For: 1.2.3, 2.0.0-beta
>         Attachments:, OpenJPA-Trunk_OJ1387.patch
> Any unique constraint declared with OpenJPA implicitly sets the respective columns to
be non-null. This is a problem if OpenJPA's mapping tool is used to create the database schema.
Even if something like @Column(nullable=true) is explicitly stated, the columns will always
be created by OpenJPA as not null.
> Modifying the database schema manually to make the columns nullable is a possible workaround.
It does not seem to cause any problems with either OpenJPA or the databases.
> I would suggest to drop the marking of unique columns as not nullable. This is done by
removing the corresponding code lines in org.apache.openjpa.jdbc.schema.Unique (trivial patch
appended to this issue). If someone wants a unique column to be not nullable, this can be
specified explicitly with @Column(nullable=false) as usual.
> I can only speculate about the reason this strange coupling of unique and nullable had
been introduced into OpenJPA. To my knowledge, it is perfectly legal use to have unique contraints
on nullable columns. In effect this means that there may be multiple rows with null values,
whilst all rows with non-null values have to be unique. ANSI SQL-92 also explicitly mentions
nullable unique columns and states that this is a crucial difference between PRIMARY KEY columns
and UNIQUE columns: the former are always not nullable, the latter may be nullable.
> This issue also pops up again and again in the user discussions, without (to my knowledge)
a single authorative answer to why this behaviour is as it is in OpenJPA. Two examples:
> My question, which remained unanswered:
> Another users question, about a month later:

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message