Community
Participate
Working Groups
Build ID: 1.0.2 Steps To Reproduce: This bug has been reported on Glassfish's bug tool but I did not see it entered here so I wanted to make sure that people were aware that it applies to EclipseLink as well. Glassfish bug: https://glassfish.dev.java.net/issues/show_bug.cgi?id=3502 Postgresql 8.3 does not support automatic typecasts anymore and EclipseLink is always binding the discriminator value as a String type which does not work for columns of type integer. The error reported from postgresql is: ERROR: operator does not exist: integer = character varying Example Class definitions: @Entity @Table(name="customfieldvalues", schema="rt") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="customfield", discriminatorType=DiscriminatorType.INTEGER) @DiscriminatorValue(value="0") public class CustomFieldValues implements Serializable { } More information: Patched diff of InheritancePolicy (as copied from the Glassfish bug): Index: foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/descriptors/InheritancePolicy.java =================================================================== --- foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/descriptors/InheritancePolicy.java (revision 3220) +++ foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/descriptors/InheritancePolicy.java (working copy) @@ -677,7 +677,17 @@ * Returns value of the abstract class indicator for the Java class. */ protected Object getClassIndicatorValue() { - return getClassIndicatorValue(getDescriptor().getJavaClass()); + Object value = getClassIndicatorValue(getDescriptor().getJavaClass()); + + if ( classIndicatorField.type == Integer.class ) { + try { + value = new Integer( ( String ) value ); + } catch ( NumberFormatException nfE ) { + // Leave value set to string. + } + } + + return value; } /** @@ -1128,8 +1138,24 @@ while (fieldValuesEnum.hasNext() && (type == null)) { Object value = fieldValuesEnum.next(); if (value.getClass() != getClass().getClass()) { - type = value.getClass(); + Class typeClass = value.getClass(); + + if (classIndicatorField.type == Integer.class) { + if (value instanceof String) { + try { + Integer.parseInt((String)value); + type = Integer.class; + } catch (NumberFormatException nfE) { + type = typeClass; + } + } else { + type = typeClass; + } + } else { + type = typeClass; + } } + } getClassIndicatorField().setType(type); }
Targetting for 1.1X since this should be considered a candidate for a patch set after 1.1
Investigating submitted fix
Created attachment 134685 [details] Alternate patch - correct discrimator value at initialization
Fix checked in. Testing added by making org.eclipse.persistence.jpa.models.inheritance.Person and its subclasses use an Integer discriminator. Tested on Oracle and PostGreSQL. Ran JPA LRG - fix only affects JPA initialization code and JPA testing Reviewed by Guy Pelletier
Mass update to change fixed in target.
*** Bug 323975 has been marked as a duplicate of this bug. ***
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink