I am setting <property name="hibernate.hbm2ddl.auto" value="update"/> in persistence.xml. In my code, if I specify @Column(unique=true, nullable=false), then database rejects the generated DDL. I am using Derby database and set "hibernate.dialect" as "org.hibernate.dialect.DerbyDialect".
The log shows the following:
INFO: table not found: IncidentStatus
Jul 16, 2006 3:28:11 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: Unsuccessful: create table IncidentStatus (id varchar(255) not null, code varchar(255) not null unique, primary key (id), unique (code))
Jul 16, 2006 3:28:11 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: Constraints 'SQL060716032811351' and 'SQL060716032811340' have the same set of columns, which is not allowed.
Hibernate version: Hibernate EntityManager 3.2.0.CR1, Hibernate Annotations 3.2.0.CR1, Hibernate 3.2 cr3
Mapping documents:
Code:
@Entity public class Incident {
@Id String id;
// See FK does *not* reference PK of IncidentStatus table
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="incidentStatus", referencedColumnName="code")
IncidentStatus incidentStatus;
}
@Entity public class IncidentStatus {
@Id String id;
@Column(name="code", unique=true, nullable=false)
String code;
@OneToOne(mappedBy="incidentStatus")
Incident incident;
}
Name and version of the database you are using:Apache Derby, version: 10.1.1.0
The generated SQL (show_sql=true): create table IncidentStatus (id varchar(255) not null, code varchar(255) not null unique, primary key (id), unique (code))