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 cc78e3eb38a..20dbec54a40 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 @@ -3021,7 +3021,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 6cac0be80ba..30a128043ce 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 @@ -1,5 +1,6 @@ /* * Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020 Payara Services Ltd. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -87,6 +88,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 +1331,18 @@ protected void initialize() { // Future: Check all is*Policy() calls this.members.put(mapping.getAttributeName(), member); } } + + 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: 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 fbc96566568..c0fb40b6741 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 @@ -1,5 +1,6 @@ /* * Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020 Payara Services Ltd. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -464,8 +465,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 @@ -477,7 +483,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();