Hibernate version:
* Hibernate Core 3.2.0.CR2
* Hibernate Annotation 3.2.0.CR1
* Hibernate Entity Manager 3.2.0.CR1
Problem
This example demonstrates two different aspects of a bug which prevents schema generation. The underlying problem seems to be that if a unique constraint is specified on the same column in two different annotations, then generated DDL tries to specify the constraint twice, which Oracle rejects.
Mapping documents:
Code:
@Entity
@Table(uniqueConstraints = { @UniqueConstraint( columnNames = { "NAME" } ) })
public class Constrained {
private long id;
private String name;
@Id
@Column(name="id", unique=true, nullable=false, insertable=true, updatable=true, precision=15, scale=0)
public long getId() {
return this.id;
}
public void setId(long id) {
this.id = id;
}
@Column(name="name", nullable=false, insertable=true, updatable=true, length=80)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
} // Constrained
Database
Oracle 10.1
Oracle JDBC Driver 10.2
Hibernate Dialect: Oracle9Dialect
Discussion
As shown above, the generated DDL is:
Quote:
create table Constrained (id number(19,0) not null unique, name varchar2(80 char) not null unique, primary key (id), unique (name))
Oracle rejects this DDL because ID and NAME each have two overlapping constraints. The problem goes away if unique=true is removed from both of the @Column annotations.
The duplicate unique specification is obvious in the NAME case, it is in the @Table and in the @Column. The duplication is only implicit in the ID case, it is specified in the @Column and implicit because it is marked @Id.
I'm not sure if this is an Annotations problem, a Tools problem or just an error in the Oracle9Dialect, and will pursue it in the appropriate forum if you can give me a hint on where to start. Thanks,
--keenan