Skip to content

Conversation

@jGauravGupta
Copy link
Member

@jGauravGupta jGauravGupta commented Apr 1, 2022

Fixes issue 1:
JPA Left Join Fetch on Embeddable ElementColection fails
#858

Fixes issue 2:
When defining a NamedQuery that has EclipseLink hints, the query fails with an exception

Exception [EclipseLink-7081] (Eclipse Persistence Services - 2.7.6.payara-p1): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The aggregate object [class be.rubus.payara.support.ticket1455.model.Tag] cannot be directly registered in the UnitOfWork.  It must be associated with the source (owner) object.
	at org.eclipse.persistence.exceptions.ValidationException.cannotRegisterAggregateObjectInUnitOfWork(ValidationException.java:622)

The offending NamedQuery, org.eclipse.persistence.config.QueryHints

@NamedQuery(
        name = "getAllBlogPosts_fail",
        query = "SELECT i FROM BlogPost i",
        hints = {
                @QueryHint(
                        name = QueryHints.REFRESH,
                        value = HintValues.TRUE
                ),
                @QueryHint(
                        name = QueryHints.LEFT_FETCH,
                        value = "i.tags"
                )
        }
)

Sample test app:
fish-406.zip

Copy link
Member

@lukasj lukasj left a comment

Choose a reason for hiding this comment

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

Needs a test, reliance on NPE being thrown is not an acceptable solution.

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.

}
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants