Hi,
I'm currently investigating using Middlegen and hbm2java to generate hbm files and java code based on an existing schema. I am using version 2.0.2 of Hibernate extensions built October 2003
I have encountered problems with the definition of native types for nullable columns by hbm2java. For example if I have an int column which is not part of any constraint and is nullable I (and I think Hibernate) would expect this column to be mapped to java.lang.Integer in the generated java class - however I get an int.
Looking at ClassMapping::initWith() below you can see that for properties 'nullable' is evaluated but not used in the call to getFieldType() and is subsequently defaulted to false. Is this a simple bug or am I missing something?
Code:
// handle in a different way id and properties...
// ids may be generated and may need to be of object type in order to support
// the unsaved-value "null" value.
// Properties may be nullable (ids may not)
if (property == id) {...
}
else {
String notnull = property.getAttributeValue("not-null");
// if not-null property is missing lets see if it has been
// defined at column level
if(notnull == null) {
Element column = property.getChild("column");
if(column != null)
notnull = column.getAttributeValue("not-null");
}
boolean nullable = ( notnull == null || notnull.equals("false") );
boolean key = property.getName().startsWith("key-"); //a composite id property
ClassName t = getFieldType(type);
addImport(t);
Field stdField =new Field(name, t, nullable && !key, key, false, metaForProperty);
fields.add(stdField );