I realize this is a very old post, but thought I'd throw some additional detail into the mix.
In your hbm.xml file you will note that the object for the view consists of a single id field. This id field is then represented as a composite id with every field being a key-property. The docs for key-property indicate that this key-property is "never null". Because this is a key-property this also means that you
can not specify not-null=false.
In org.hibernate.type.ComponentType you will find the code...
Code:
public Object hydrate(
final ResultSet rs,
final String[] names,
final SessionImplementor session,
final Object owner)
throws HibernateException, SQLException {
int begin = 0;
boolean notNull = false;
Object[] values = new Object[propertySpan];
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 ) {
//AZG - incorrect behavior for composite keys built on views? So long as
// one value is not null the key is valid, no?
return null; //different nullability rules for pk/fk
}
}
else {
notNull = true;
}
values[i] = val;
begin += length;
}
return notNull ? values : null;
}
...this is the heart of the matter. Note the AZG comment I have inserted. If any field is null then a null result will be returned. I'm not sure if this line could simply be commented out or if this would break composite keys elsewhere (e.g. composite primary key relationships ). Since a view might contain fields that are null this breaks the contract implied by the docs for the schema, but it seems to me like this is a shortfall in the reveng/ORM capabilities...
Anyway, thought I would throw this into the post for posterity.[/b]