openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeremy Bauer (JIRA)" <>
Subject [jira] Created: (OPENJPA-756) Mapping tool fails with duplicate unique constraint on @Id field if @Column(unique=true)
Date Thu, 30 Oct 2008 21:16:46 GMT
Mapping tool fails with duplicate unique constraint on @Id field if @Column(unique=true)

                 Key: OPENJPA-756
             Project: OpenJPA
          Issue Type: Bug
          Components: sql
    Affects Versions: 2.0.0
         Environment: Derby, Oracle, possibly other DBs
            Reporter: Jeremy Bauer
            Priority: Minor

The runtime mapping tool (openjpa.jdbc.SynchronizeMappings=buildSchema) fails to create a
table if the @Column annotation with unique=true attribute is specified on a field tagged
with @Id.  ex:

    @Column(name="uniqueid", unique=true)
    private int id;

OpenJPA generates a unique constraint on the field along with the primary key constraint.
 Derby, Oracle, and possibly other databases fail with a message to the effect that  OpenJPA
is trying to create a duplicate constraint.  Primary keys are unique by definition so OpenJPA
should not create the unnecessary extra unique constraint.

Here's an example of the failure using Derby:

Constraints 'UNQ_' and 'SQL081030035840490' have the same set of columns, which is not allowed.
 {stmnt 2175170 CREATE TABLE UniqueIDEntity (uniqueid INTEGER NOT NULL, name VARCHAR(255),
PRIMARY KEY (uniqueid), CONSTRAINT UNQ_ UNIQUE (uniqueid))} [code=30000, state=42Z93]

Some database may allow/require this behavior, so investigation will need to be done to determine
if there will be special handling for some databases vs. others.

The simple workaround is to remove the unique attribute on an @Id column.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message