|
In Hibernate 4.2.2, the issue is still here.
I have an entity which I load using a @Loader & a @NamedNativeQuery. The SQLQueryReturnProcessor (line 198) creates a ColumnEntityAliases (SQLQueryReturnProcessor.java, line 198). This which uses "property column names" for "property aliases" (ColumnEntityAliases .java, line 55).
However, if a property has been defined by a formula, there's no "property column names" for this property. And then it results in a NPE when the aliases are interned (DefaultEntityAliases.java, line 193).
I suppose the following code can fix the problem
@Override
protected String[] getPropertyAliases(Loadable persister, int j) {
String[] propertyAliases = persister.getPropertyColumnNames(j);
boolean hasNull = propertyAliases == null;
if (!hasNull) {
for (int i = 0; i < propertyAliases.length; i++) {
if (propertyAliases[i] == null) {
if (hasNull) {
LOGGER.trace(
"Property column names aren't all nulls ! (persister={},index={},columns={})",
persister, j, Arrays.toString(propertyAliases)
);
break;
}
hasNull = true;
}
}
}
if (hasNull) {
propertyAliases = super.getPropertyAliases(persister, j);
}
return propertyAliases;
}
|