Saturday, January 26, 2008

Hibernate Bugs

When I was working with my pet project using hibernate JPA (core 3.2.5 GA) and found that a bug in the following function

public void validateColumns(Dialect dialect, Mapping mapping, TableMetadata tableInfo) {
Iterator iter = getColumnIterator();
while ( iter.hasNext() ) {
Column col = (Column) iter.next();

ColumnMetadata columnInfo = tableInfo.getColumnMetadata( col.getName() );

if ( columnInfo == null ) {
throw new HibernateException( "Missing column: " + col.getName() + " in " + Table.qualify( tableInfo.getCatalog(), tableInfo.getSchema(), tableInfo.getName()));
}
else {
final boolean typesMatch = col.getSqlType( dialect, mapping )
.startsWith( columnInfo.getTypeName().toLowerCase() )
|| columnInfo.getTypeCode() == col.getSqlTypeCode( mapping );
if ( !typesMatch ) {
throw new HibernateException(
"Wrong column type: " + col.getName() +
", expected: " + col.getSqlType( dialect, mapping )
);
}
}
}

}
Basicallly, when you use columnDefinition you have to use the lowercase, as following:
@Column(name = "xxxx", columnDefinition = "text", nullable = false)


and this won't work
@Column(name = "request_url", columnDefinition = "TEXT", nullable = false)
The bug is in the red line that one part converted to lowercase, not another.

Just to be clkear, I have tried to post this on the hibernate forum but cannot register since I got all the code errors and timed out. so I gave up.

No comments: