|
281 | 281 | import static org.hibernate.internal.util.collections.CollectionHelper.toSmallList; |
282 | 282 | import static org.hibernate.loader.ast.internal.MultiKeyLoadHelper.supportsSqlArrayType; |
283 | 283 | import static org.hibernate.metamodel.RepresentationMode.POJO; |
| 284 | +import static org.hibernate.metamodel.mapping.EntityDiscriminatorMapping.DISCRIMINATOR_ROLE_NAME; |
284 | 285 | import static org.hibernate.metamodel.mapping.internal.GeneratedValuesProcessor.getGeneratedAttributes; |
285 | 286 | import static org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper.buildBasicAttributeMapping; |
286 | 287 | import static org.hibernate.metamodel.mapping.internal.MappingModelCreationHelper.buildEncapsulatedCompositeIdentifierMapping; |
@@ -1766,7 +1767,7 @@ protected void initializeLazyProperty(Object entity, EntityEntry entry, Object p |
1766 | 1767 | setPropertyValue( entity, index, propValue ); |
1767 | 1768 | final var loadedState = entry.getLoadedState(); |
1768 | 1769 | if ( loadedState != null ) { |
1769 | | - // object have been loaded with setReadOnly(true); HHH-2236 |
| 1770 | + // object has been loaded with setReadOnly(true); HHH-2236 |
1770 | 1771 | loadedState[index] = type.deepCopy( propValue, factory ); |
1771 | 1772 | } |
1772 | 1773 | // If the entity has deleted state, then update that as well |
@@ -2281,7 +2282,7 @@ private DiscriminatorType<?> buildDiscriminatorType() { |
2281 | 2282 | discriminatorBasicType, |
2282 | 2283 | new UnifiedAnyDiscriminatorConverter<>( |
2283 | 2284 | getNavigableRole() |
2284 | | - .append( EntityDiscriminatorMapping.DISCRIMINATOR_ROLE_NAME ), |
| 2285 | + .append( DISCRIMINATOR_ROLE_NAME ), |
2285 | 2286 | factory.getTypeConfiguration().getJavaTypeRegistry() |
2286 | 2287 | .resolveDescriptor( discriminatedType() ), |
2287 | 2288 | discriminatorBasicType.getRelationalJavaType(), |
@@ -3465,9 +3466,9 @@ public void addDiscriminatorToInsertGroup(MutationGroupBuilder insertGroupBuilde |
3465 | 3466 | public void addSoftDeleteToInsertGroup(MutationGroupBuilder insertGroupBuilder) { |
3466 | 3467 | if ( softDeleteMapping != null ) { |
3467 | 3468 | final TableInsertBuilder insertBuilder = insertGroupBuilder.getTableDetailsBuilder( getIdentifierTableName() ); |
3468 | | - final MutatingTableReference mutatingTable = insertBuilder.getMutatingTable(); |
3469 | | - final ColumnReference columnReference = new ColumnReference( mutatingTable, softDeleteMapping ); |
3470 | | - final ColumnValueBinding nonDeletedValueBinding = softDeleteMapping.createNonDeletedValueBinding( columnReference ); |
| 3469 | + final var mutatingTable = insertBuilder.getMutatingTable(); |
| 3470 | + final var columnReference = new ColumnReference( mutatingTable, softDeleteMapping ); |
| 3471 | + final var nonDeletedValueBinding = softDeleteMapping.createNonDeletedValueBinding( columnReference ); |
3471 | 3472 | insertBuilder.addValueColumn( nonDeletedValueBinding ); |
3472 | 3473 | } |
3473 | 3474 | } |
@@ -3512,7 +3513,7 @@ private Object doLoad(Object id, Object optionalObject, LockOptions lockOptions, |
3512 | 3513 | CORE_LOGGER.fetchingEntity( infoString( this, id, getFactory() ) ); |
3513 | 3514 | } |
3514 | 3515 |
|
3515 | | - final SingleIdEntityLoader<?> loader = determineLoaderToUse( session, lockOptions ); |
| 3516 | + final var loader = determineLoaderToUse( session, lockOptions ); |
3516 | 3517 | return optionalObject == null |
3517 | 3518 | ? loader.load( id, lockOptions, readOnly, session ) |
3518 | 3519 | : loader.load( id, optionalObject, lockOptions, readOnly, session ); |
@@ -3558,47 +3559,57 @@ public Object initializeEnhancedEntityUsedAsProxy( |
3558 | 3559 | Object entity, |
3559 | 3560 | String nameOfAttributeBeingAccessed, |
3560 | 3561 | SharedSessionContractImplementor session) { |
3561 | | - final var enhancementMetadata = getBytecodeEnhancementMetadata(); |
3562 | | - if ( enhancementMetadata.extractLazyInterceptor( entity ) |
| 3562 | + if ( getBytecodeEnhancementMetadata().extractLazyInterceptor( entity ) |
3563 | 3563 | instanceof EnhancementAsProxyLazinessInterceptor proxyInterceptor ) { |
3564 | | - |
3565 | 3564 | final var entityKey = proxyInterceptor.getEntityKey(); |
3566 | | - final Object identifier = entityKey.getIdentifier(); |
3567 | | - |
3568 | | - Object loaded = null; |
3569 | | - if ( canReadFromCache && session.isEventSource() ) { |
3570 | | - final var eventSource = (EventSource) session; |
3571 | | - loaded = eventSource.loadFromSecondLevelCache( this, entityKey, entity, LockMode.NONE ); |
3572 | | - } |
3573 | | - if ( loaded == null ) { |
3574 | | - final var lockOptions = new LockOptions(); |
3575 | | - loaded = determineLoaderToUse( session, lockOptions ).load( identifier, entity, lockOptions, session ); |
3576 | | - } |
3577 | | - |
| 3565 | + final Object id = entityKey.getIdentifier(); |
| 3566 | + final Object loaded = loadEnhancedEntityUsedAsProxy( entity, session, entityKey ); |
3578 | 3567 | if ( loaded == null ) { |
3579 | 3568 | final var persistenceContext = session.getPersistenceContext(); |
3580 | 3569 | persistenceContext.removeEntry( entity ); |
3581 | 3570 | persistenceContext.removeEntity( entityKey ); |
3582 | | - factory.getEntityNotFoundDelegate().handleEntityNotFound( entityKey.getEntityName(), identifier ); |
| 3571 | + factory.getEntityNotFoundDelegate().handleEntityNotFound( entityKey.getEntityName(), id ); |
3583 | 3572 | } |
| 3573 | + return readEnhancedEntityAttribute( entity, id, nameOfAttributeBeingAccessed, session ); |
| 3574 | + } |
| 3575 | + else { |
| 3576 | + throw new AssertionFailure( "The BytecodeLazyAttributeInterceptor was not an instance of EnhancementAsProxyLazinessInterceptor" ); |
| 3577 | + } |
| 3578 | + } |
3584 | 3579 |
|
3585 | | - final var interceptor = enhancementMetadata.injectInterceptor( entity, identifier, session ); |
3586 | | - |
3587 | | - final Object value; |
3588 | | - if ( nameOfAttributeBeingAccessed == null ) { |
3589 | | - return null; |
3590 | | - } |
3591 | | - else if ( interceptor.isAttributeLoaded( nameOfAttributeBeingAccessed ) ) { |
3592 | | - value = getPropertyValue( entity, nameOfAttributeBeingAccessed ); |
3593 | | - } |
3594 | | - else { |
3595 | | - value = initializeLazyProperty( nameOfAttributeBeingAccessed, entity, session ); |
| 3580 | + private Object loadEnhancedEntityUsedAsProxy( |
| 3581 | + Object entity, |
| 3582 | + SharedSessionContractImplementor session, |
| 3583 | + EntityKey entityKey) { |
| 3584 | + if ( canReadFromCache && session.isEventSource() ) { |
| 3585 | + final Object cachedEntity = |
| 3586 | + session.loadFromSecondLevelCache( this, entityKey, entity, LockMode.NONE ); |
| 3587 | + if ( cachedEntity != null ) { |
| 3588 | + return cachedEntity; |
3596 | 3589 | } |
3597 | | - |
3598 | | - return interceptor.readObject( entity, nameOfAttributeBeingAccessed, value ); |
3599 | 3590 | } |
| 3591 | + final var lockOptions = new LockOptions(); |
| 3592 | + return determineLoaderToUse( session, lockOptions ) |
| 3593 | + .load( entityKey.getIdentifier(), entity, lockOptions, session ); |
| 3594 | + } |
3600 | 3595 |
|
3601 | | - throw new IllegalStateException(); |
| 3596 | + private Object readEnhancedEntityAttribute( |
| 3597 | + Object entity, Object id, String nameOfAttributeBeingAccessed, |
| 3598 | + SharedSessionContractImplementor session) { |
| 3599 | + final var interceptor = |
| 3600 | + getBytecodeEnhancementMetadata() |
| 3601 | + .injectInterceptor( entity, id, session ); |
| 3602 | + final Object value; |
| 3603 | + if ( nameOfAttributeBeingAccessed == null ) { |
| 3604 | + return null; |
| 3605 | + } |
| 3606 | + else if ( interceptor.isAttributeLoaded( nameOfAttributeBeingAccessed ) ) { |
| 3607 | + value = getPropertyValue( entity, nameOfAttributeBeingAccessed ); |
| 3608 | + } |
| 3609 | + else { |
| 3610 | + value = initializeLazyProperty( nameOfAttributeBeingAccessed, entity, session ); |
| 3611 | + } |
| 3612 | + return interceptor.readObject( entity, nameOfAttributeBeingAccessed, value ); |
3602 | 3613 | } |
3603 | 3614 |
|
3604 | 3615 | @Override |
|
0 commit comments