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

HHH-19248 Return of deleted entities doesn't work with naturalid multiloading #9924

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jrenaat
Copy link
Member

@jrenaat jrenaat commented Mar 27, 2025


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-19248

@jrenaat jrenaat force-pushed the HHH-19248_multinaturalid branch 2 times, most recently from 7a7f8d6 to 3771c29 Compare March 31, 2025 21:40
@jrenaat jrenaat force-pushed the HHH-19248_multinaturalid branch from 3771c29 to f9a8c34 Compare April 1, 2025 11:08
@jrenaat jrenaat requested a review from sebersole April 1, 2025 13:09
@jrenaat jrenaat changed the title HHH-19248 Return of deleted entities doesn't work with naturalid multiloading - DO NOT MERGE HHH-19248 Return of deleted entities doesn't work with naturalid multiloading Apr 1, 2025
@jrenaat jrenaat requested a review from gavinking April 4, 2025 20:40
Comment on lines +141 to +186
protected void performAnyNeededCrossReferenceSynchronizations() {
final NaturalIdMapping naturalIdMapping = entityDescriptor.getNaturalIdMapping();

if ( !naturalIdMapping.isMutable() ) {
// only mutable natural-ids need this processing
return;
}

if ( ! session.isTransactionInProgress() ) {
// not in a transaction so skip synchronization
return;
}

final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final Collection<?> cachedPkResolutions =
persistenceContext.getNaturalIdResolutions()
.getCachedPkResolutions( entityDescriptor );
final boolean loggerDebugEnabled = LoaderLogging.LOADER_LOGGER.isDebugEnabled();
for ( Object pk : cachedPkResolutions ) {
final EntityKey entityKey = session.generateEntityKey( pk, entityDescriptor );
final Object entity = persistenceContext.getEntity( entityKey );
final EntityEntry entry = persistenceContext.getEntry( entity );

if ( entry == null ) {
if ( loggerDebugEnabled ) {
LoaderLogging.LOADER_LOGGER.debugf(
"Cached natural-id/pk resolution linked to null EntityEntry in persistence context : %s#%s",
entityDescriptor.getEntityName(),
pk
);
}
continue;
}

if ( !entry.requiresDirtyCheck( entity ) ) {
continue;
}

// MANAGED is the only status we care about here...
if ( entry.getStatus() != Status.MANAGED ) {
continue;
}

persistenceContext.getNaturalIdResolutions().handleSynchronization( pk, entity, entityDescriptor );
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this just a copy/paste job from BaseNaturalIdLoadAccessImpl?

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.

2 participants