Skip to content

Commit

Permalink
[hibernate#1627] fix for @SQLSelect annotation on a primary entity
Browse files Browse the repository at this point in the history
  • Loading branch information
blafond committed Jul 17, 2023
1 parent 29c518e commit e3d0979
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

return completedFuture( query.uniqueResult() );
return ( (ReactiveNativeQueryImpl) query ).reactiveUnique();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit e3d0979

Please sign in to comment.