-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-19248 Return of deleted entities doesn't work with naturalid multiloading #9924
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
hibernate-core/src/main/java/org/hibernate/generator/internal/NaturalIdHelper.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
hibernate-core/src/main/java/org/hibernate/internal/NaturalIdHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.internal; | ||
|
|
||
| import org.hibernate.engine.spi.EntityEntry; | ||
| import org.hibernate.engine.spi.EntityKey; | ||
| import org.hibernate.engine.spi.PersistenceContext; | ||
| import org.hibernate.engine.spi.SharedSessionContractImplementor; | ||
| import org.hibernate.engine.spi.Status; | ||
| import org.hibernate.id.IdentifierGenerationException; | ||
| import org.hibernate.loader.LoaderLogging; | ||
| import org.hibernate.metamodel.mapping.EntityMappingType; | ||
| import org.hibernate.metamodel.mapping.NaturalIdMapping; | ||
| import org.hibernate.persister.entity.EntityPersister; | ||
|
|
||
| import java.util.Collection; | ||
|
|
||
| /** | ||
| * @author Gavin King | ||
| */ | ||
| public class NaturalIdHelper { | ||
| public static String[] getNaturalIdPropertyNames(EntityPersister persister) { | ||
| final int[] naturalIdPropertyIndices = persister.getNaturalIdentifierProperties(); | ||
| if ( naturalIdPropertyIndices == null ) { | ||
| throw new IdentifierGenerationException( "Entity '" + persister.getEntityName() | ||
| + "' has no '@NaturalId' property" ); | ||
| } | ||
| if ( persister.getEntityMetamodel().isNaturalIdentifierInsertGenerated() ) { | ||
| throw new IdentifierGenerationException( "Entity '" + persister.getEntityName() | ||
| + "' has a '@NaturalId' property which is also defined as insert-generated" ); | ||
| } | ||
| final String[] allPropertyNames = persister.getPropertyNames(); | ||
| final String[] propertyNames = new String[naturalIdPropertyIndices.length]; | ||
| for ( int i = 0; i < naturalIdPropertyIndices.length; i++ ) { | ||
| propertyNames[i] = allPropertyNames[naturalIdPropertyIndices[i]]; | ||
| } | ||
| return propertyNames; | ||
| } | ||
|
|
||
| public static void performAnyNeededCrossReferenceSynchronizations( | ||
| boolean synchronizationEnabled, | ||
| EntityMappingType entityMappingType, | ||
| SharedSessionContractImplementor session) { | ||
|
|
||
| if ( !synchronizationEnabled ) { | ||
| // synchronization (this process) was disabled | ||
| return; | ||
| } | ||
|
|
||
| final NaturalIdMapping naturalIdMapping = entityMappingType.getNaturalIdMapping(); | ||
|
|
||
| if ( !naturalIdMapping.isMutable() ) { | ||
| // only mutable natural-ids need this processing | ||
| return; | ||
| } | ||
|
|
||
| if ( ! session.isTransactionInProgress() ) { | ||
| // not in a transaction so skip synchronization | ||
| return; | ||
| } | ||
|
|
||
| final EntityPersister entityPersister = entityMappingType.getEntityPersister(); | ||
|
|
||
| final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); | ||
| final Collection<?> cachedPkResolutions = | ||
| persistenceContext.getNaturalIdResolutions() | ||
| .getCachedPkResolutions( entityPersister ); | ||
| final boolean loggerDebugEnabled = LoaderLogging.LOADER_LOGGER.isDebugEnabled(); | ||
| for ( Object pk : cachedPkResolutions ) { | ||
| final EntityKey entityKey = session.generateEntityKey( pk, entityPersister ); | ||
| 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", | ||
| entityMappingType.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, entityPersister ); | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.