Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Left Join Fetch on Embeddable ElementColection fails & NamedQuery with QueryHints.REFRESH fails to execute #1465

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3021,7 +3021,7 @@ public Object internalRegisterObject(Object object, ClassDescriptor descriptor,
return null;
}
if (descriptor.isDescriptorTypeAggregate()) {
throw ValidationException.cannotRegisterAggregateObjectInUnitOfWork(object.getClass());
return null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate why this is fixing the issue? Technically I see you are stopping the exception from being thrown, of course. Is this a try-and-error fix, or some deeper understanding? To me it seems the method should not have been called in the first place for those aggregates.

}
Object registeredObject = checkIfAlreadyRegistered(object, descriptor);
if (registeredObject == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed at the origin of failure.

AbstractSessionLog.getLog().log(SessionLog.FINE, "Caught NPE when preinitializing database mapping",
npe.getMessage());
}
}
}

/**
* INTERNAL:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<ManagedTypeImpl<?>>(managedTypes.values())) {
managedType.preinitaliseMappings(session);
}

/**
* Delayed-Initialization (process all mappings) of all Managed types
Expand All @@ -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();
Expand Down