HHH-13377 Lazy loaded properties of bytecode enhanced entity are left stale after refresh of entity
This commit is contained in:
parent
ad5855f4b1
commit
4ebbf5b36d
|
@ -198,4 +198,8 @@ public class LazyAttributeLoadingInterceptor extends AbstractLazyLoadInterceptor
|
|||
}
|
||||
mutableLazyFields.add( fieldName );
|
||||
}
|
||||
|
||||
public void clearInitializedLazyFields() {
|
||||
initializedLazyFields = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ import org.hibernate.LockOptions;
|
|||
import org.hibernate.NonUniqueObjectException;
|
||||
import org.hibernate.TransientObjectException;
|
||||
import org.hibernate.UnresolvableObjectException;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor;
|
||||
import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata;
|
||||
import org.hibernate.cache.spi.access.CollectionDataAccess;
|
||||
import org.hibernate.cache.spi.access.EntityDataAccess;
|
||||
import org.hibernate.cache.spi.access.SoftLock;
|
||||
|
@ -189,6 +191,14 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
|
|||
EntityEntry entry,
|
||||
Object id,
|
||||
PersistenceContext persistenceContext) {
|
||||
final BytecodeEnhancementMetadata instrumentationMetadata = persister.getInstrumentationMetadata();
|
||||
if ( object != null && instrumentationMetadata.isEnhancedForLazyLoading() ) {
|
||||
final LazyAttributeLoadingInterceptor interceptor = instrumentationMetadata.extractInterceptor( object );
|
||||
if ( interceptor != null ) {
|
||||
// The list of initialized lazy fields have to be cleared in order to refresh them from the database.
|
||||
interceptor.clearInitializedLazyFields();
|
||||
}
|
||||
}
|
||||
|
||||
final Object result = source.getLoadQueryInfluencers().fromInternalFetchProfile(
|
||||
CascadingFetchProfile.REFRESH,
|
||||
|
|
|
@ -13,7 +13,6 @@ import jakarta.persistence.ManyToOne;
|
|||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import org.hibernate.annotations.Formula;
|
||||
import org.hibernate.dialect.MariaDBDialect;
|
||||
import org.hibernate.dialect.MySQLDialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
|
||||
|
@ -44,8 +43,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
|||
@BytecodeEnhanced
|
||||
@SkipForDialectGroup(
|
||||
{
|
||||
@SkipForDialect( dialectClass = MySQLDialect.class, reason = "does not support || as String concatenation"),
|
||||
@SkipForDialect( dialectClass = MariaDBDialect.class, reason = "does not support || as String concatenation"),
|
||||
@SkipForDialect( dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "does not support || as String concatenation"),
|
||||
@SkipForDialect( dialectClass = SQLServerDialect.class, reason = "does not support || as String concatenation"),
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue