HHH-17049 Bytecode Enhancement, extra records created for associations created in constructor

(cherry picked from commit 3ef251dfb2)
This commit is contained in:
Andrea Boriero 2023-09-06 17:05:28 +02:00 committed by Christian Beikov
parent ad55143eb5
commit 5e17e121ef
2 changed files with 12 additions and 8 deletions

View File

@ -87,11 +87,16 @@ public final class Cascade {
LOG.tracev( "Processing cascade {0} for: {1}", action, persister.getEntityName() );
}
final PersistenceContext persistenceContext = eventSource.getPersistenceContextInternal();
final EntityEntry entry = persistenceContext.getEntry( parent );
if ( entry != null && entry.getLoadedState() == null && entry.getStatus() == Status.MANAGED && persister.getBytecodeEnhancementMetadata()
.isEnhancedForLazyLoading() ) {
return;
}
final Type[] types = persister.getPropertyTypes();
final String[] propertyNames = persister.getPropertyNames();
final CascadeStyle[] cascadeStyles = persister.getPropertyCascadeStyles();
final boolean hasUninitializedLazyProperties = persister.hasUninitializedLazyProperties( parent );
for ( int i = 0; i < types.length; i++) {
final CascadeStyle style = cascadeStyles[ i ];
final String propertyName = propertyNames[ i ];
@ -109,7 +114,7 @@ public final class Cascade {
// If parent is a detached entity being merged,
// then parent will not be in the PersistenceContext
// (so lazy attributes must not be initialized).
if ( persistenceContext.getEntry( parent ) == null ) {
if ( entry == null ) {
// parent was not in the PersistenceContext
continue;
}

View File

@ -139,9 +139,8 @@ public abstract class AbstractFlushingEventListener implements JpaBootstrapSensi
//safe from concurrent modification because of how concurrentEntries() is implemented on IdentityMap
for ( Map.Entry<Object,EntityEntry> me : persistenceContext.reentrantSafeEntityEntries() ) {
// for ( Map.Entry me : IdentityMap.concurrentEntries( persistenceContext.getEntityEntries() ) ) {
EntityEntry entry = me.getValue();
Status status = entry.getStatus();
if ( status == Status.MANAGED || status == Status.SAVING || status == Status.READ_ONLY ) {
final EntityEntry entry = me.getValue();
if ( flushable( entry ) ) {
cascadeOnFlush( session, entry.getPersister(), me.getKey(), context );
}
}
@ -149,9 +148,9 @@ public abstract class AbstractFlushingEventListener implements JpaBootstrapSensi
private static boolean flushable(EntityEntry entry) {
final Status status = entry.getStatus();
return ( status == Status.MANAGED && entry.getLoadedState() != null )
|| status == Status.SAVING
|| status == Status.READ_ONLY;
return status == Status.MANAGED
|| status == Status.SAVING
|| status == Status.READ_ONLY;
}
private void cascadeOnFlush(EventSource session, EntityPersister persister, Object object, PersistContext anything)