Skip to content

Backports #2026 and #2060 #2068

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 6 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.hibernate.reactive.persister.entity.impl.ReactiveEntityPersister;
import org.hibernate.reactive.session.impl.ReactiveQueryExecutorLookup;
import org.hibernate.reactive.session.impl.ReactiveSessionImpl;
import org.hibernate.type.CollectionType;
import org.hibernate.type.EntityType;
import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.OneToOneType;
Expand Down Expand Up @@ -137,7 +138,7 @@ static CompletionStage<Object> loadByUniqueKey(
else {
return persister
.reactiveLoadByUniqueKey( uniqueKeyPropertyName, key, session )
.thenApply( ukResult -> loadHibernateProxyEntity( ukResult, session )
.thenCompose( ukResult -> loadHibernateProxyEntity( ukResult, session )
.thenApply( targetUK -> {
persistenceContext.addEntity( euk, targetUK );
return targetUK;
Expand All @@ -158,42 +159,8 @@ public static CompletionStage<Object[]> replace(
final Object owner,
final Map<Object, Object> copyCache) {
Object[] copied = new Object[original.length];
for ( int i = 0; i < types.length; i++ ) {
if ( original[i] == UNFETCHED_PROPERTY || original[i] == UNKNOWN ) {
copied[i] = target[i];
}
else {
if ( !( types[i] instanceof EntityType ) ) {
copied[i] = types[i].replace(
original[i],
target[i] == UNFETCHED_PROPERTY ? null : target[i],
session,
owner,
copyCache
);
}
}
}
return loop( 0, types.length,
i -> original[i] != UNFETCHED_PROPERTY && original[i] != UNKNOWN
&& types[i] instanceof EntityType,
i -> replace(
(EntityType) types[i],
original[i],
target[i] == UNFETCHED_PROPERTY ? null : target[i],
session,
owner,
copyCache
).thenCompose( copy -> {
if ( copy instanceof CompletionStage ) {
return ( (CompletionStage<?>) copy )
.thenAccept( nonStageCopy -> copied[i] = nonStageCopy );
}
else {
copied[i] = copy;
return voidFuture();
}
} )
return loop(
0, types.length, i -> replace( original, target, types, session, owner, copyCache, i, copied )
).thenApply( v -> copied );
}

Expand All @@ -209,43 +176,9 @@ public static CompletionStage<Object[]> replace(
final Map<Object, Object> copyCache,
final ForeignKeyDirection foreignKeyDirection) {
Object[] copied = new Object[original.length];
for ( int i = 0; i < types.length; i++ ) {
if ( original[i] == UNFETCHED_PROPERTY || original[i] == UNKNOWN ) {
copied[i] = target[i];
}
else {
if ( !( types[i] instanceof EntityType ) ) {
copied[i] = types[i].replace(
original[i],
target[i] == UNFETCHED_PROPERTY ? null : target[i],
session,
owner,
copyCache,
foreignKeyDirection
);
}
}
}
return loop( 0, types.length,
i -> original[i] != UNFETCHED_PROPERTY && original[i] != UNKNOWN
&& types[i] instanceof EntityType,
i -> replace(
(EntityType) types[i],
original[i],
target[i] == UNFETCHED_PROPERTY ? null : target[i],
session,
owner,
copyCache,
foreignKeyDirection
).thenCompose( copy -> {
if ( copy instanceof CompletionStage ) {
return ( (CompletionStage<?>) copy ).thenAccept( nonStageCopy -> copied[i] = nonStageCopy );
}
else {
copied[i] = copy;
return voidFuture();
}
} )
return loop(
0, types.length,
i -> replace( original, target, types, session, owner, copyCache, foreignKeyDirection, i, copied )
).thenApply( v -> copied );
}

Expand All @@ -272,7 +205,7 @@ private static CompletionStage<Object> replace(
/**
* @see EntityType#replace(Object, Object, SharedSessionContractImplementor, Object, Map)
*/
private static CompletionStage<Object> replace(
protected static CompletionStage<Object> replace(
EntityType entityType,
Object original,
Object target,
Expand Down Expand Up @@ -336,15 +269,16 @@ private static CompletionStage<Object> resolveIdOrUniqueKey(
// as a ComponentType. In the case that the entity is unfetched, we need to
// explicitly fetch it here before calling replace(). (Note that in Hibernate
// ORM this is unnecessary due to transparent lazy fetching.)
return ( (ReactiveSessionImpl) session ).reactiveFetch( id, true )
return ( (ReactiveSessionImpl) session )
.reactiveFetch( id, true )
.thenCompose( fetched -> {
Object idOrUniqueKey = entityType.getIdentifierOrUniqueKeyType( session.getFactory() )
Object idOrUniqueKey = entityType
.getIdentifierOrUniqueKeyType( session.getFactory() )
.replace( fetched, null, session, owner, copyCache );
if ( idOrUniqueKey instanceof CompletionStage ) {
return ( (CompletionStage<?>) idOrUniqueKey )
.thenCompose( key -> resolve( entityType, key, owner, session ) );
}

return resolve( entityType, idOrUniqueKey, owner, session );
} );
} );
Expand Down Expand Up @@ -426,9 +360,9 @@ private static CompletionStage<Object> getIdentifierFromHibernateProxy(
if ( type.isEntityIdentifierMapping() ) {
propertyValue = getIdentifier( (EntityType) type, propertyValue, (SessionImplementor) session );
}
return completedFuture( propertyValue );
return propertyValue;
}
return nullFuture();
return null;
} );
}

Expand All @@ -450,4 +384,100 @@ private static CompletionStage<Object> loadHibernateProxyEntity(
}
}

private static CompletionStage<Void> replace(
Object[] original,
Object[] target,
Type[] types,
SessionImplementor session,
Object owner,
Map<Object, Object> copyCache,
int i,
Object[] copied) {
if ( original[i] == UNFETCHED_PROPERTY || original[i] == UNKNOWN ) {
copied[i] = target[i];
return voidFuture();
}
else if ( types[i] instanceof CollectionType ) {
return CollectionTypes.replace(
(CollectionType) types[i],
original[i],
target[i] == UNFETCHED_PROPERTY ? null : target[i],
session,
owner,
copyCache
).thenAccept( copy -> copied[i] = copy );
}
else if ( types[i] instanceof EntityType ) {
return replace(
(EntityType) types[i],
original[i],
target[i] == UNFETCHED_PROPERTY ? null : target[i],
session,
owner,
copyCache
).thenAccept( copy -> copied[i] = copy );
}
else {
final Type type = types[i];
copied[i] = type.replace(
original[i],
target[i] == UNFETCHED_PROPERTY ? null : target[i],
session,
owner,
copyCache
);
return voidFuture();
}
}

private static CompletionStage<Void> replace(
Object[] original,
Object[] target,
Type[] types,
SessionImplementor session,
Object owner,
Map<Object, Object> copyCache,
ForeignKeyDirection foreignKeyDirection,
int i,
Object[] copied) {
if ( original[i] == UNFETCHED_PROPERTY || original[i] == UNKNOWN ) {
copied[i] = target[i];
return voidFuture();
}
else if ( types[i] instanceof CollectionType ) {
return CollectionTypes.replace(
(CollectionType) types[i],
original[i],
target[i] == UNFETCHED_PROPERTY ? null : target[i],
session,
owner,
copyCache,
foreignKeyDirection
).thenAccept( copy -> copied[i] = copy );
}
else if ( types[i] instanceof EntityType ) {
return replace(
(EntityType) types[i],
original[i],
target[i] == UNFETCHED_PROPERTY ? null : target[i],
session,
owner,
copyCache,
foreignKeyDirection
).thenAccept( copy -> copied[i] = copy );
}
else {
copied[i] = types[i].replace(
original[i],
target[i] == UNFETCHED_PROPERTY ? null : target[i],
session,
owner,
copyCache,
foreignKeyDirection
);
return voidFuture();
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,8 @@ public interface Log extends BasicLogger {
@LogMessage(level = WARN)
@Message(id = 448, value = "Warnings creating temp table : %s")
void warningsCreatingTempTable(SQLWarning warning);

@LogMessage(level = WARN)
@Message( id= 494, value = "Attempt to merge an uninitialized collection with queued operations; queued operations will be ignored: %s")
void ignoreQueuedOperationsOnMerge(String collectionInfoString);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.hibernate.sql.results.graph.InitializerParent;
import org.hibernate.sql.results.graph.embeddable.EmbeddableInitializer;
import org.hibernate.sql.results.graph.embeddable.internal.EmbeddableForeignKeyResultImpl;
import org.hibernate.sql.results.graph.embeddable.internal.EmbeddableInitializerImpl;

public class ReactiveEmbeddableForeignKeyResultImpl<T> extends EmbeddableForeignKeyResultImpl<T> {

Expand All @@ -22,6 +21,6 @@ public ReactiveEmbeddableForeignKeyResultImpl(EmbeddableForeignKeyResultImpl<T>
public EmbeddableInitializer<?> createInitializer(InitializerParent parent, AssemblerCreationState creationState) {
return getReferencedModePart() instanceof NonAggregatedIdentifierMapping
? new ReactiveNonAggregatedIdentifierMappingInitializer( this, null, creationState, true )
: new EmbeddableInitializerImpl( this, null, null, creationState, true );
: new ReactiveEmbeddableInitializerImpl( this, null, null, creationState, true );
}
}
Loading
Loading