Hi Hibernate-Team,
I think I found a bug in the ddl-generation out of an annotated entity.
Trying Hibernate 3.6.1 and 3.6.3
I have an entity containing a column with an max length as shown below:
Code:
@Column(name = "Name", columnDefinition = "varchar", length = 100)
private String name;
The generated DDL looks like this, but it doesn't contain the expected length:
Code:
create table Category (
id bigint identity not null,
name varchar null,
primary key (id)
)
After debugging I recognized an strange behaviour inside the Method:
org.hibernate.mapping.Column.getSqlType(Dialect dialect, Mapping mapping)
Code:
public String getSqlType(Dialect dialect, Mapping mapping) throws HibernateException {
return sqlType==null ?
dialect.getTypeName( getSqlTypeCode(mapping), getLength(), getPrecision(), getScale() ) :
sqlType;
}
The sqlType is not null, so this method returns "varchar", but the method "dialect.getTypeName" would return "varchar(100)". So I think the method should look SOMETHING like this:
Code:
public String getSqlType(Dialect dialect, Mapping mapping) throws HibernateException {
if(sqlType == null || sqlType.equals("varchar")) {
return dialect.getTypeName( getSqlTypeCode(mapping), getLength(), getPrecision(), getScale() ) ;
} else {
return sqlType;
}
}
What do you think?
Greetings,
Sebastian