Skip to content

Commit

Permalink
[hibernate#1831] Upgrade Hibernate ORM to 6.4.1.Final
Browse files Browse the repository at this point in the history
Some minor changes in Hibernate ORM
in the way entity are initialized caused
compilation and runtime errors in Hibernate Reactive.
  • Loading branch information
DavideD committed Jan 10, 2024
1 parent f9ea159 commit 5c85650
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 48 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ version = projectVersion
// ./gradlew clean build -PhibernateOrmVersion=5.6.15-SNAPSHOT
ext {
if ( !project.hasProperty('hibernateOrmVersion') ) {
hibernateOrmVersion = '6.4.0.Final'
hibernateOrmVersion = '6.4.1.Final'
}
if ( !project.hasProperty( 'hibernateOrmGradlePluginVersion' ) ) {
// Same as ORM as default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,6 @@ private CompletionStage<Object> loadWithRegularProxy(LoadEvent event, EntityPers
return narrowedProxy( event, persister, keyToLoad, options, proxy );
}
else if ( options.isAllowProxyCreation() ) {
// return a new proxy
// ORM calls DefaultLoadEventListener#proxyOrCache
return completedFuture( proxyOrCached( event, persister, keyToLoad, options ) );
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,24 @@ public void onPostLoad(PostLoadEvent event) {
callbackRegistry.postLoad( entity );

final EventSource session = event.getSession();
final EntityEntry entry = session.getPersistenceContextInternal().getEntry( entity );
final EntityEntry entry = session.getPersistenceContextInternal().getEntry( entity );
if ( entry == null ) {
throw new AssertionFailure( "possible non-threadsafe access to the session" );
}

final ReactiveActionQueue actionQueue = ((ReactiveSession) session).getReactiveActionQueue();
final ReactiveActionQueue actionQueue = ( (ReactiveSession) session ).getReactiveActionQueue();
switch ( entry.getLockMode() ) {
// case PESSIMISTIC_FORCE_INCREMENT:
// This case is handled by DefaultReactiveLoadEventListener
case PESSIMISTIC_FORCE_INCREMENT:
// This case is handled by DefaultReactiveLoadEventListener
break;
case OPTIMISTIC_FORCE_INCREMENT:
actionQueue.registerProcess( new ReactiveEntityIncrementVersionProcess( entity ) );
break;
case OPTIMISTIC:
actionQueue.registerProcess( new ReactiveEntityVerifyVersionProcess( entity ) );
break;
default:
// Nothing to do
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,23 @@ public CompletionStage<Void> reactiveInitializeInstance(ReactiveRowProcessingSta
return voidFuture()
.thenCompose( v -> {
if ( lazyInitializer != null ) {
return lazyInitialize( rowProcessingState, lazyInitializer );
final SharedSessionContractImplementor session = rowProcessingState.getSession();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final EntityHolder holder = persistenceContext.getEntityHolder( getEntityKey() );
Object instance = holder.getEntity();
assert instance != null : "The real entity instance must be resolved in the `resolveInstance()` phase";
if ( holder.getEntityInitializer() == this ) {
return initializeEntity( instance, rowProcessingState )
.thenAccept( vv -> {
lazyInitializer.setImplementation( instance );
setEntityInstanceForNotify( instance );
} );
}
return voidFuture().thenAccept( vv -> {
lazyInitializer.setImplementation( instance );
setEntityInstanceForNotify( instance );

} );
}
else {
// FIXME: Read from cache if possible
Expand All @@ -103,35 +119,6 @@ public CompletionStage<Void> reactiveInitializeInstance(ReactiveRowProcessingSta
return voidFuture();
}

private CompletionStage<Void> lazyInitialize(ReactiveRowProcessingState rowProcessingState, LazyInitializer lazyInitializer) {
final SharedSessionContractImplementor session = rowProcessingState.getSession();
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
final EntityHolder holder = persistenceContext.getEntityHolder( getEntityKey() );
Object instance = holder.getEntity();
if ( instance == null ) {
return resolveInstance( rowProcessingState, lazyInitializer, persistenceContext );
}
lazyInitializer.setImplementation( instance );
setEntityInstanceForNotify( instance );
return voidFuture();
}

private CompletionStage<Void> resolveInstance(
ReactiveRowProcessingState rowProcessingState,
LazyInitializer lazyInitializer,
PersistenceContext persistenceContext) {
final Object instance = super.resolveInstance(
getEntityKey().getIdentifier(),
persistenceContext.getEntityHolder( getEntityKey() ),
rowProcessingState
);
return initializeEntity( instance, rowProcessingState )
.thenAccept( v -> {
lazyInitializer.setImplementation( instance );
setEntityInstanceForNotify( instance );
} );
}

private CompletionStage<Void> initializeEntity(Object toInitialize, RowProcessingState rowProcessingState) {
if ( !skipInitialization( toInitialize, rowProcessingState ) ) {
assert consistentInstance( toInitialize, rowProcessingState );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,29 @@ public ReactiveEntitySelectFetchByUniqueKeyInitializer(

@Override
public CompletionStage<Void> reactiveInitializeInstance(ReactiveRowProcessingState rowProcessingState) {
if ( entityInstance != null || isInitialized ) {
if ( getEntityInstance() != null || isEntityInitialized() ) {
return voidFuture();
}
state = State.RESOLVED;

final EntityInitializer parentEntityInitializer = getParentEntityInitializer( parentAccess );
if ( parentEntityInitializer != null && parentEntityInitializer.getEntityKey() != null ) {
// make sure parentEntityInitializer.resolveInstance has been called before
parentEntityInitializer.resolveInstance( rowProcessingState );
if ( parentEntityInitializer.isEntityInitialized() ) {
isInitialized = true;
initializeState();
return voidFuture();
}
}

if ( !isAttributeAssignableToConcreteDescriptor() ) {
isInitialized = true;
initializeState();
return voidFuture();
}

final Object entityIdentifier = keyAssembler.assemble( rowProcessingState );
if ( entityIdentifier == null ) {
isInitialized = true;
initializeState();
return voidFuture();
}
final String entityName = concreteDescriptor.getEntityName();
Expand Down Expand Up @@ -104,7 +105,7 @@ public CompletionStage<Void> reactiveInitializeInstance(ReactiveRowProcessingSta
if ( entityInstance != null ) {
setEntityInstance( persistenceContext.proxyFor( entityInstance ) );
}
isInitialized = true;
initializeState();
return voidFuture();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,18 @@ public CompletionStage<Void> reactiveInitializeInstance(ReactiveRowProcessingSta

final EntityInitializer parentEntityInitializer = parentAccess.findFirstEntityInitializer();
if ( parentEntityInitializer != null && parentEntityInitializer.isEntityInitialized() ) {
isInitialized = true;
initializeState();
return voidFuture();
}

if ( !isAttributeAssignableToConcreteDescriptor() ) {
initializeState();
return voidFuture();
}

final Object entityIdentifier = keyAssembler.assemble( rowProcessingState );
if ( entityIdentifier == null ) {
isInitialized = true;
initializeState();
return voidFuture();
}

Expand Down Expand Up @@ -145,7 +146,7 @@ public CompletionStage<Void> reactiveInitializeInstance(ReactiveRowProcessingSta
entityInstance = holder.getEntity();
if ( holder.getEntityInitializer() == null ) {
if ( entityInstance != null && Hibernate.isInitialized( entityInstance ) ) {
isInitialized = true;
initializeState();
return voidFuture();
}
}
Expand All @@ -159,11 +160,11 @@ else if ( holder.getEntityInitializer() != this ) {
holder.getEntityInitializer()
);
}
isInitialized = true;
initializeState();
return voidFuture();
}
else if ( entityInstance == null ) {
isInitialized = true;
initializeState();
return voidFuture();
}
}
Expand Down Expand Up @@ -202,11 +203,15 @@ else if ( entityInstance == null ) {
if ( lazyInitializer != null ) {
lazyInitializer.setUnwrap( unwrapProxy );
}
isInitialized = true;
initializeState();
return voidFuture();
} );
}

protected void initializeState() {
state = State.INITIALIZED;
}

protected ToOneAttributeMapping toOneMapping() {
return (ToOneAttributeMapping) getInitializedPart();
}
Expand Down

0 comments on commit 5c85650

Please sign in to comment.