| Hi Koen, it is the other way around. Given the following class structur
@MappedSuperclass
public class UniqueEntity implements Serializable {
public static final String UUID_NULL = "00000000-0000-0000-0000-000000000000";
private static final long serialVersionUID = -3610403242496914987L;
@Id
@Column(columnDefinition = "uniqueidentifier")
private String uuid;
protected UniqueEntity() {
this.setUuid(UUID.randomUUID().toString().toUpperCase());
}
public UniqueEntity(String uuid) {
this.setUuid(UUID.fromString(uuid).toString().toUpperCase());
}
@Override
public int hashCode() {
return this.getUuid().hashCode();
}
@Override
public boolean equals(java.lang.Object object) {
if (object instanceof UniqueEntity) {
return this.getUuid().equals(((UniqueEntity) object).getUuid());
}
if (object instanceof String) {
return this.getUuid().equals(object);
}
return super.equals(object);
}
@Override
public String toString() {
return this.getUuid();
}
public String getUuid() {
return this.uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}
@Entity(name = "Test")
@Table(name = "\"Test\"")
@AttributeOverride(name = "uuid",
column = @Column(columnDefinition = "varchar", name = "\"uuid\"", length = 36))
public class Test extends UniqueEntity implements Serializable {
private static final long serialVersionUID = -4887208830019935105L;
}
Hibernate generates the following table creation script for Test entity
create table "Test" (
"uuid" varchar not null,
primary key ("uuid")
)
Where I would expect the following
The class UniqueEntity is a base class shared across multiple projects primarily designed for SQLServer databases and therefore annotaded with “uniqueidentifier” column definition. As one project uses a H2 database which does not have such a data type the class Test is annotated with @AttributeOverride to switch to “varchar” type with a specific length of 36. But the length property is ignored by the script generation tool. |