I have a problem after migrating to hibernate3 (3.0.1):
In an exsiting data model, I have a table without primary key. That's odd, but with hibernate2 it worked. With middlegen I generated a mapping file with a composite id using all columns. Read access via HQL statements worked fine.
Now with with hibernate3, the resulting list contains only nulls instead of the entity instances!!! After debugging, I found a code change in class ComponentType function hydrate(). The hibernate2 code was:
Code:
for ( int i=0; i<propertySpan; i++ ) {
int length = propertyTypes[i].getColumnSpan( session.getFactory() );
String[] range = ArrayHelper.slice(names, begin, length); //cache this
Object val = propertyTypes[i].hydrate(rs, range, session, owner);
if (val!=null) notNull=true;
values[i] = val;
begin+=length;
}
In hibernate3 it was changed to
Code:
for ( int i = 0; i < propertySpan; i++ ) {
int length = propertyTypes[i].getColumnSpan( session.getFactory() );
String[] range = ArrayHelper.slice( names, begin, length ); //cache this
Object val = propertyTypes[i].hydrate( rs, range, session, owner );
if ( val == null ) {
if (isKey) return null; //different nullability rules for pk/fk
}
else {
notNull = true;
}
values[i] = val;
begin += length;
}
This means, if a value of a key column is null, the whole key is considered to be null!!??
In my case, the composite-id contains all columns of the table and some of them are nullable. When I try to load such an entity, a null in a column leads to a null key and this leads to null entities!
I know having a table without primary key is not a great data model, but this is an old existing model. And with hibernate2 it worked - this seemed to be a big migration issue.
Any comments, workarounds etc?