Subject Re: [Firebird-Java] Primary key column marked as unique in reverse-engineering using hibernate tools
Author Lester Caine
vkozlov_tk wrote:
> When I perform reverse-engineering of a Firebird database using
> hibernate tools, the primary key column is annotated as unique:
>
> CREATE TABLE OBJCLASS (
> IDOBJCLASS INTEGER NOT NULL,
> NAME VARCHAR(250),
> SYSNAME VARCHAR(250) NOT NULL,
> IDOBJCLASSPARENT INTEGER
> );
> ALTER TABLE OBJCLASS ADD PRIMARY KEY (IDOBJCLASS);
>
> generates code for primary key:
>
> @SequenceGenerator(name = "generator", sequenceName = "GENERATOR_ID")
> @Id
> @GeneratedValue(strategy = SEQUENCE, generator = "generator")
> @Column(name = "IDOBJCLASS", unique = true, nullable = false)
> public Integer getIdobjclass() {
> return this.idobjclass;
> }
>
> and when I trying to recrerate database via hbm2ddl, the error occurs:
>
> 1485 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - GDS
> Exception. 335544351. unsuccessful metadata update
> Same set of columns cannot be used in more than one PRIMARY KEY and/or
> UNIQUE constraint definition
>
> The similar issue described here:
> http://opensource.atlassian.com/projects/hibernate/browse/HBX-978
>
> Is there any way to suppress generation of "unique = true" for PK
> column?

The bug you list also contains part of the reason that it happens. This
depends on which database engine you are using as I think MySQL at least needs
the unique=true. So perhaps the problem is with the recreate rather then the
reverse-engineering. In other cross database software, the 'datadict' side of
things has to compensate for these differences. It depends which bug you are
trying to fix?

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php