Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 346106

Summary: Canonical Model initialization fails with FieldNotFoundException with virtual mappings
Product: z_Archived Reporter: Doug Clarke <douglas.clarke>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED FIXED QA Contact:
Severity: major    
Priority: P3 CC: michael.f.obrien
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Doug Clarke CLA 2011-05-17 11:19:10 EDT
When initializing the metamodel and an Attribute field cannot be found on the canonical model class the initialization fails with a ValidationException wrapping the FieldNotFoundException.

I propose that an Attribute in the Metamodel not being found in the canonical metamodel class should be ignored during initialization. The canonical model is used at design time to build criteria queries so it missing at runtime has little effect.

The following patch ignores this case and also makes the getMapping() public on AttributeImpl so that the mapping can be accessed externally through the metamodel downcasting.

Index: src/org/eclipse/persistence/internal/jpa/EntityManagerSetupImpl.java
===================================================================
--- src/org/eclipse/persistence/internal/jpa/EntityManagerSetupImpl.java    (revision 9393)
+++ src/org/eclipse/persistence/internal/jpa/EntityManagerSetupImpl.java    (working copy)
@@ -2531,8 +2531,9 @@
                          } else {
                             PrivilegedAccessHelper.getDeclaredField(clazz, fieldName, false).set(clazz, attribute);
                          } 
-                    }
-                    catch (Exception e) {
+                    } catch (NoSuchFieldException nsfe) {
+                        // Ignore fields missing in canonical model
+                    } catch (Exception e) {
                        ValidationException v = ValidationException.invalidFieldForClass(fieldName, clazz);
                        v.setInternalException(e);
                        throw v;
Index: src/org/eclipse/persistence/internal/jpa/metamodel/AttributeImpl.java
===================================================================
--- src/org/eclipse/persistence/internal/jpa/metamodel/AttributeImpl.java    (revision 9393)
+++ src/org/eclipse/persistence/internal/jpa/metamodel/AttributeImpl.java    (working copy)
@@ -207,7 +207,7 @@
      * Return the databaseMapping that represents the type
      * @return
      */
-    protected DatabaseMapping getMapping() {
+    public DatabaseMapping getMapping() {
         return this.mapping;
     }
Comment 1 Michael OBrien CLA 2011-05-17 14:43:18 EDT
>both changes look good to me, visibility change for non-spec getMapping() is good.
Comment 2 Doug Clarke CLA 2011-06-03 13:38:27 EDT
fixed with the final ASM upgrade issues.
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:27:41 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink