Skip to content

Commit 71f28e5

Browse files
committed
[#1627] fix for @SQLSelect annotation on a primary entity
1 parent 29c518e commit 71f28e5

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ast/internal/ReactiveSingleIdEntityLoaderProvidedQueryImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.hibernate.query.named.NamedQueryMemento;
1616
import org.hibernate.query.spi.QueryImplementor;
1717
import org.hibernate.reactive.loader.ast.spi.ReactiveSingleIdEntityLoader;
18+
import org.hibernate.reactive.query.ReactiveSelectionQuery;
1819

1920
import jakarta.persistence.Parameter;
2021

@@ -51,7 +52,7 @@ public CompletionStage<T> load(Object pkValue, LockOptions lockOptions, Boolean
5152
query.setParameter( (Parameter<Object>) query.getParameters().iterator().next(), pkValue );
5253
query.setHibernateFlushMode( FlushMode.MANUAL );
5354

54-
return completedFuture( query.uniqueResult() );
55+
return ( (ReactiveSelectionQuery) query ).reactiveUnique();
5556
}
5657

5758
@Override

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/internal/ReactiveNamedObjectRepositoryImpl.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public ReactiveNamedObjectRepositoryImpl(NamedObjectRepository delegate) {
3232

3333
@Override
3434
public NamedSqmQueryMemento getSqmQueryMemento(String queryName) {
35-
return wrap( delegate.getSqmQueryMemento( queryName ) );
35+
return wrapSqmQueryMemento( delegate.getSqmQueryMemento( queryName ) );
3636
}
3737

3838
@Override
@@ -47,7 +47,7 @@ public void registerSqmQueryMemento(String name, NamedSqmQueryMemento descriptor
4747

4848
@Override
4949
public NamedNativeQueryMemento getNativeQueryMemento(String queryName) {
50-
return wrap( delegate.getNativeQueryMemento( queryName ) );
50+
return wrapNativeQueryMemento( delegate.getNativeQueryMemento( queryName ) );
5151
}
5252

5353
@Override
@@ -105,7 +105,7 @@ public NamedQueryMemento resolve(
105105
SessionFactoryImplementor sessionFactory,
106106
MetadataImplementor bootMetamodel,
107107
String registrationName) {
108-
return delegate.resolve( sessionFactory, bootMetamodel, registrationName );
108+
return wrap(delegate.resolve( sessionFactory, bootMetamodel, registrationName ));
109109
}
110110

111111
@Override
@@ -118,7 +118,17 @@ public void close() {
118118
delegate.close();
119119
}
120120

121-
private static NamedSqmQueryMemento wrap(final NamedSqmQueryMemento sqmQueryMemento) {
121+
private static NamedQueryMemento wrap(final NamedQueryMemento namedQueryMemento) {
122+
if ( namedQueryMemento == null ) {
123+
return null;
124+
} else if( namedQueryMemento instanceof NamedSqmQueryMemento ) {
125+
return wrapSqmQueryMemento( (NamedSqmQueryMemento) namedQueryMemento );
126+
} else {
127+
return wrapNativeQueryMemento( (NamedNativeQueryMemento) namedQueryMemento );
128+
}
129+
}
130+
131+
private static NamedSqmQueryMemento wrapSqmQueryMemento(final NamedSqmQueryMemento sqmQueryMemento) {
122132
if ( sqmQueryMemento == null ) {
123133
return null;
124134
}
@@ -131,7 +141,7 @@ else if ( sqmQueryMemento instanceof ReactiveNamedSqmQueryMemento ) {
131141
}
132142
}
133143

134-
private static NamedNativeQueryMemento wrap(final NamedNativeQueryMemento nativeQueryMemento) {
144+
private static NamedNativeQueryMemento wrapNativeQueryMemento(final NamedNativeQueryMemento nativeQueryMemento) {
135145
if ( nativeQueryMemento == null ) {
136146
return null;
137147
}

0 commit comments

Comments
 (0)