You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Jeremias Maerki (JIRA)" <ji...@apache.org> on 2009/05/08 09:53:45 UTC
[jira] Commented: (OPENJPA-756) Mapping tool fails with duplicate
unique constraint on @Id field if @Column(unique=true)
[ https://issues.apache.org/jira/browse/OPENJPA-756?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12707270#action_12707270 ]
Jeremias Maerki commented on OPENJPA-756:
-----------------------------------------
If the primary key field is a String (ex. a URI as in my case), even the work-around doesn't help:
@Id
@Column(name="URI")
public String getUriString() {
return this.uriString;
}
OpenJPA 1.2.1 creates for Derby:
CREATE TABLE RepresentationType (URI VARCHAR(255) NOT NULL, contentType VARCHAR(255), PRIMARY KEY (URI), CONSTRAINT UNQ_URI UNIQUE (URI))
> Mapping tool fails with duplicate unique constraint on @Id field if @Column(unique=true)
> ----------------------------------------------------------------------------------------
>
> Key: OPENJPA-756
> URL: https://issues.apache.org/jira/browse/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:
> @Id
> @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.