diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdEntityLoaderProvidedQueryImpl.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdEntityLoaderProvidedQueryImpl.java index f509eb9a24..cad4efa68c 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdEntityLoaderProvidedQueryImpl.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdEntityLoaderProvidedQueryImpl.java @@ -15,6 +15,7 @@ import org.hibernate.query.named.NamedQueryMemento; import org.hibernate.query.spi.QueryImplementor; import org.hibernate.reactive.loader.ast.spi.ReactiveSingleIdEntityLoader; +import org.hibernate.reactive.query.sql.internal.ReactiveNativeQueryImpl; import jakarta.persistence.Parameter; @@ -51,7 +52,7 @@ public CompletionStage load(Object pkValue, LockOptions lockOptions, Boolean query.setParameter( (Parameter) query.getParameters().iterator().next(), pkValue ); query.setHibernateFlushMode( FlushMode.MANUAL ); - return completedFuture( query.uniqueResult() ); + return ( (ReactiveNativeQueryImpl) query ).reactiveUnique(); } @Override diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/internal/ReactiveNamedObjectRepositoryImpl.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/internal/ReactiveNamedObjectRepositoryImpl.java index f4d8da437f..52d778e1a9 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/internal/ReactiveNamedObjectRepositoryImpl.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/internal/ReactiveNamedObjectRepositoryImpl.java @@ -32,7 +32,7 @@ public ReactiveNamedObjectRepositoryImpl(NamedObjectRepository delegate) { @Override public NamedSqmQueryMemento getSqmQueryMemento(String queryName) { - return wrap( delegate.getSqmQueryMemento( queryName ) ); + return wrapSqmQueryMemento( delegate.getSqmQueryMemento( queryName ) ); } @Override @@ -47,7 +47,7 @@ public void registerSqmQueryMemento(String name, NamedSqmQueryMemento descriptor @Override public NamedNativeQueryMemento getNativeQueryMemento(String queryName) { - return wrap( delegate.getNativeQueryMemento( queryName ) ); + return wrapNativeQueryMemento( delegate.getNativeQueryMemento( queryName ) ); } @Override @@ -105,7 +105,7 @@ public NamedQueryMemento resolve( SessionFactoryImplementor sessionFactory, MetadataImplementor bootMetamodel, String registrationName) { - return delegate.resolve( sessionFactory, bootMetamodel, registrationName ); + return wrap(delegate.resolve( sessionFactory, bootMetamodel, registrationName )); } @Override @@ -118,7 +118,17 @@ public void close() { delegate.close(); } - private static NamedSqmQueryMemento wrap(final NamedSqmQueryMemento sqmQueryMemento) { + private static NamedQueryMemento wrap(final NamedQueryMemento namedQueryMemento) { + if ( namedQueryMemento == null ) { + return null; + } else if( namedQueryMemento instanceof NamedSqmQueryMemento ) { + return wrapSqmQueryMemento( (NamedSqmQueryMemento) namedQueryMemento ); + } else { + return wrapNativeQueryMemento( (NamedNativeQueryMemento) namedQueryMemento ); + } + } + + private static NamedSqmQueryMemento wrapSqmQueryMemento(final NamedSqmQueryMemento sqmQueryMemento) { if ( sqmQueryMemento == null ) { return null; } @@ -131,7 +141,7 @@ else if ( sqmQueryMemento instanceof ReactiveNamedSqmQueryMemento ) { } } - private static NamedNativeQueryMemento wrap(final NamedNativeQueryMemento nativeQueryMemento) { + private static NamedNativeQueryMemento wrapNativeQueryMemento(final NamedNativeQueryMemento nativeQueryMemento) { if ( nativeQueryMemento == null ) { return null; }