From 18530211685239f027f541600199f0bf5cf49888 Mon Sep 17 00:00:00 2001 From: Kalin Chan Date: Tue, 24 Sep 2024 14:00:52 +0100 Subject: [PATCH] Left Join Fetch on Embeddable ElementColection fails & NamedQuery with QueryHints.REFRESH fails to execute --- .../internal/sessions/UnitOfWorkImpl.java | 2 +- .../internal/jpa/metamodel/ManagedTypeImpl.java | 13 +++++++++++++ .../internal/jpa/metamodel/MetamodelImpl.java | 11 ++++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/UnitOfWorkImpl.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/UnitOfWorkImpl.java index 8f642d48831..ce5dec6aff6 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/UnitOfWorkImpl.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/UnitOfWorkImpl.java @@ -3051,7 +3051,7 @@ public Object internalRegisterObject(Object object, ClassDescriptor descriptor, return null; } if (descriptor.isDescriptorTypeAggregate()) { - throw ValidationException.cannotRegisterAggregateObjectInUnitOfWork(object.getClass()); + return null; } Object registeredObject = checkIfAlreadyRegistered(object, descriptor); if (registeredObject == null) { diff --git a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/metamodel/ManagedTypeImpl.java b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/metamodel/ManagedTypeImpl.java index 515708f213e..acc0f25ee1e 100644 --- a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/metamodel/ManagedTypeImpl.java +++ b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/metamodel/ManagedTypeImpl.java @@ -87,6 +87,7 @@ import org.eclipse.persistence.internal.security.PrivilegedAccessHelper; import org.eclipse.persistence.internal.security.PrivilegedGetDeclaredField; import org.eclipse.persistence.internal.security.PrivilegedGetDeclaredMethod; +import org.eclipse.persistence.internal.sessions.AbstractSession; import org.eclipse.persistence.logging.AbstractSessionLog; import org.eclipse.persistence.logging.SessionLog; import org.eclipse.persistence.mappings.CollectionMapping; @@ -1329,6 +1330,18 @@ protected void initialize() { // Future: Check all is*Policy() calls } } + public void preinitaliseMappings(AbstractSession session) { + for (DatabaseMapping mapping : getDescriptor().getMappings()) { + try { + mapping.preInitialize(session); + } catch (NullPointerException npe) { + // A NPE gets thrown if the expected method is not present for the mapping + AbstractSessionLog.getLog().log(SessionLog.FINE, "Caught NPE when preinitializing database mapping", + npe.getMessage()); + } + } + } + /** * INTERNAL: * Get the elementType directly from the class using a reflective method call diff --git a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/metamodel/MetamodelImpl.java b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/metamodel/MetamodelImpl.java index 6b3040fe8d2..a02c3ea8acc 100644 --- a/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/metamodel/MetamodelImpl.java +++ b/jpa/org.eclipse.persistence.jpa/src/main/java/org/eclipse/persistence/internal/jpa/metamodel/MetamodelImpl.java @@ -497,8 +497,13 @@ public void initialize(ClassLoader classLoader) { } } - //1 - process all non-mappedSuperclass types first, so we pick up attribute types - //2 - process mappedSuperclass types and lookup collection attribute types on inheriting entity types when field is not set + //1 - preinitalise all mappings so attribute types are set + //2 - process all non-mappedSuperclass types first so we pick up attribute types + //3 - process mappedSuperclass types and lookup collection attribute types on inheriting entity types when field is not set + + for(ManagedTypeImpl managedType : new ArrayList<>(managedTypes.values())) { + managedType.preinitaliseMappings(session); + } /* * Delayed-Initialization (process all mappings) of all Managed types @@ -510,7 +515,7 @@ public void initialize(ClassLoader classLoader) { managedType.initialize(); } - // 3 - process all the Id attributes on each IdentifiableType + // 4 - process all the Id attributes on each IdentifiableType for(ManagedTypeImpl potentialIdentifiableType : managedTypes.values()) { if(potentialIdentifiableType.isIdentifiableType()) { ((IdentifiableTypeImpl)potentialIdentifiableType).initializeIdAttributes();