Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 346106 - Canonical Model initialization fails with FieldNotFoundException with virtual mappings
Summary: Canonical Model initialization fails with FieldNotFoundException with virtual...
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-17 11:19 EDT by Doug Clarke CLA
Modified: 2022-06-09 10:27 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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