Hi,
Thomas Dudziak wrote:
Brian Latimer wrote:
I get a NPE when representsNull is called on an anonymous field with a value of 0.
I can tell at least why this is happening: anonymous fields have no representation in the java classes, and thus no associated java field type (AnonymousPersistentField.getType() always returns null). So if you're using numeric values in the anonymous field, the representsNull method tries to check whether the type of the anonymous field is primitive which obviously fails.
I'm no expert on anonymous fields, but the solution could be to provide a reverse lookup "jdbc type -> java type" for anonymous fields which provides a sensible java type (in your case probably Double or BigDecimal).
Anonymous fields doesn't have a representation in the persistent object, thus it will never be a primitive java field pendant. Thus I think the patch provided by Phil Denis
I would suggest the following patch:
public boolean representsNull(FieldDescriptor fld, Object aValue)
{
if(aValue == null) return true;boolean result = false;
if(((aValue instanceof Number) && (((Number) aValue).longValue() == 0)))
{
// PATCH STARTS HERE
PersistentField field = fld.getPersistentField();
Class type = field.getType();
// AnonymousPersistentFields will *always* have a null type according to the
// javadoc comments in AnonymousPersistentField.getType()
if (type == null) {
return true;
}
result = type.isPrimitive();
// PATCH ENDS HERE
}
else if((aValue instanceof String) && (((String) aValue).length() == 0))
{
result = fld.isPrimaryKey();
}
return result;
}
should be ok - except one difference: He always return 'true' for anonymous fields, I would suggest always return 'false', because the anonymous field never represents a primitive field with value 0.
regards, Armin
Tom
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
