Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 261368 - DiscriminatorType.INTEGER is ignored on DiscriminatorColumn which causes postgresql 8.3 error
Summary: DiscriminatorType.INTEGER is ignored on DiscriminatorColumn which causes post...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard: submitted_patch
Keywords:
: 323975 (view as bug list)
Depends on:
Blocks: 284351
  Show dependency tree
 
Reported: 2009-01-16 11:50 EST by Tommy Odom CLA
Modified: 2022-06-09 10:30 EDT (History)
3 users (show)

See Also:


Attachments
Alternate patch - correct discrimator value at initialization (9.24 KB, patch)
2009-05-06 15:50 EDT, Tom Ware CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tommy Odom CLA 2009-01-16 11:50:13 EST
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);
                 }
Comment 1 Tom Ware CLA 2009-01-21 13:23:06 EST
Targetting for 1.1X since this should be considered a candidate for a patch set after 1.1
Comment 2 Tom Ware CLA 2009-05-06 11:38:21 EDT
Investigating submitted fix
Comment 3 Tom Ware CLA 2009-05-06 15:50:46 EDT
Created attachment 134685 [details]
Alternate patch - correct discrimator value at initialization
Comment 4 Tom Ware CLA 2009-05-06 16:02:43 EDT
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
Comment 5 Peter Krogh CLA 2009-08-26 09:46:07 EDT
Mass update to change fixed in target.
Comment 6 Peter Krogh CLA 2009-08-26 09:48:28 EDT
Mass update to change fixed in target.
Comment 7 Peter Krogh CLA 2009-08-26 09:53:02 EDT
Mass update to change fixed in target.
Comment 8 Peter Krogh CLA 2009-08-26 09:55:33 EDT
Mass update to change fixed in target.
Comment 9 Guy Pelletier CLA 2010-09-10 09:13:36 EDT
*** Bug 323975 has been marked as a duplicate of this bug. ***
Comment 10 Eclipse Webmaster CLA 2022-06-09 10:30:37 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink