Skip to content
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

[DON'T MERGE] HHH-18629 Fix inconsistent column alias generated while result class is used for placeholder #9418

Draft
wants to merge 1 commit into
base: 6.6
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public String getHqlString() {
public NamedSqmQueryMemento resolve(SessionFactoryImplementor factory) {
return new NamedHqlQueryMementoImpl(
getRegistrationName(),
null,
hqlString,
firstResult,
maxResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.hibernate.query.sql.internal.NamedNativeQueryMementoImpl;
import org.hibernate.query.sql.spi.NamedNativeQueryMemento;

import org.checkerframework.checker.nullness.qual.Nullable;

import static org.hibernate.internal.util.StringHelper.isNotEmpty;

/**
Expand Down Expand Up @@ -86,15 +88,16 @@ public String getResultSetMappingClassName() {

@Override
public NamedNativeQueryMemento resolve(SessionFactoryImplementor factory) {
Class<?> resultClass = isNotEmpty( resultSetMappingClassName )
? factory.getServiceRegistry().requireService( ClassLoaderService.class ).classForName( resultSetMappingClassName )
: null;
return new NamedNativeQueryMementoImpl(
getRegistrationName(),
resultClass,
sqlString,
sqlString,
resultSetMappingName,
isNotEmpty( resultSetMappingClassName )
? factory.getServiceRegistry().requireService( ClassLoaderService.class )
.classForName( resultSetMappingClassName )
: null,
resultClass,
querySpaces,
getCacheable(),
getCacheRegion(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.function.Function;

import jakarta.persistence.EntityGraph;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.hibernate.CacheMode;
import org.hibernate.EntityNameResolver;
import org.hibernate.Filter;
Expand Down Expand Up @@ -891,22 +892,8 @@ public <T> QueryImplementor<T> createQuery(String queryString, Class<T> expected
// dynamic native (SQL) query handling

@Override @SuppressWarnings("rawtypes")
public NativeQueryImpl createNativeQuery(String sqlString) {
checkOpen();
pulseTransactionCoordinator();
delayedAfterCompletion();

try {
final NativeQueryImpl query = new NativeQueryImpl<>( sqlString, this );
if ( isEmpty( query.getComment() ) ) {
query.setComment( "dynamic native SQL query" );
}
applyQuerySettingsAndHints( query );
return query;
}
catch (RuntimeException he) {
throw getExceptionConverter().convert( he );
}
public NativeQueryImplementor createNativeQuery(String sqlString) {
return createNativeQuery( sqlString, (Class) null );
}

@Override @SuppressWarnings("rawtypes")
Expand Down Expand Up @@ -939,12 +926,28 @@ protected NamedResultSetMappingMemento getResultSetMappingMemento(String resultS
@Override @SuppressWarnings({"rawtypes", "unchecked"})
//note: we're doing something a bit funny here to work around
// the clashing signatures declared by the supertypes
public NativeQueryImplementor createNativeQuery(String sqlString, Class resultClass) {
final NativeQueryImpl query = createNativeQuery( sqlString );
addResultType( resultClass, query );
return query;
public NativeQueryImplementor createNativeQuery(String sqlString, @Nullable Class resultClass) {
checkOpen();
pulseTransactionCoordinator();
delayedAfterCompletion();

try {
final NativeQueryImpl query = new NativeQueryImpl<>( sqlString, resultClass, this );
if ( isEmpty( query.getComment() ) ) {
query.setComment( "dynamic native SQL query" );
}
applyQuerySettingsAndHints( query );
return query;
}
catch (RuntimeException he) {
throw getExceptionConverter().convert( he );
}
}

/**
* @deprecated Use {@link NativeQueryImpl#NativeQueryImpl(String, Class, SharedSessionContractImplementor)} instead
*/
@Deprecated(forRemoval = true)
protected <T> void addResultType(Class<T> resultClass, NativeQueryImplementor<T> query) {
if ( Tuple.class.equals( resultClass ) ) {
query.setTupleTransformer( NativeQueryTupleTransformer.INSTANCE );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public NamedCallableQueryMementoImpl(
Map<String, Object> hints) {
super(
name,
Object.class,
cacheable,
cacheRegion,
cacheMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.hibernate.query.sqm.spi.NamedSqmQueryMemento;
import org.hibernate.query.sqm.tree.SqmStatement;

import org.checkerframework.checker.nullness.qual.Nullable;

public class NamedCriteriaQueryMementoImpl extends AbstractNamedQueryMemento implements NamedSqmQueryMemento, Serializable {

private final SqmStatement sqmStatement;
Expand All @@ -33,6 +35,7 @@ public class NamedCriteriaQueryMementoImpl extends AbstractNamedQueryMemento imp

public NamedCriteriaQueryMementoImpl(
String name,
@Nullable Class<?> resultType,
SqmStatement sqmStatement,
Integer firstResult,
Integer maxResults,
Expand All @@ -47,7 +50,7 @@ public NamedCriteriaQueryMementoImpl(
String comment,
Map<String, String> parameterTypes,
Map<String, Object> hints) {
super( name, cacheable, cacheRegion, cacheMode, flushMode, readOnly, timeout, fetchSize, comment, hints );
super( name, resultType, cacheable, cacheRegion, cacheMode, flushMode, readOnly, timeout, fetchSize, comment, hints );
this.sqmStatement = sqmStatement;
this.firstResult = firstResult;
this.maxResults = maxResults;
Expand Down Expand Up @@ -114,6 +117,7 @@ public Map<String, String> getParameterTypes() {
public NamedSqmQueryMemento makeCopy(String name) {
return new NamedCriteriaQueryMementoImpl(
name,
getResultType(),
sqmStatement,
firstResult,
maxResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.hibernate.query.sqm.spi.NamedSqmQueryMemento;
import org.hibernate.query.sqm.tree.SqmStatement;

import org.checkerframework.checker.nullness.qual.Nullable;

/**
* Definition of a named query, defined in the mapping metadata.
* Additionally, as of JPA 2.1, named query definition can also come
Expand All @@ -41,6 +43,7 @@ public class NamedHqlQueryMementoImpl extends AbstractNamedQueryMemento implemen

public NamedHqlQueryMementoImpl(
String name,
@Nullable Class<?> resultType,
String hqlString,
Integer firstResult,
Integer maxResults,
Expand All @@ -57,6 +60,7 @@ public NamedHqlQueryMementoImpl(
Map<String,Object> hints) {
super(
name,
resultType,
cacheable,
cacheRegion,
cacheMode,
Expand Down Expand Up @@ -103,6 +107,7 @@ public Map<String, String> getParameterTypes() {
public NamedSqmQueryMemento makeCopy(String name) {
return new NamedHqlQueryMementoImpl(
name,
getResultType(),
hqlString,
firstResult,
maxResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
import org.hibernate.CacheMode;
import org.hibernate.FlushMode;

import org.checkerframework.checker.nullness.qual.Nullable;

/**
* @author Steve Ebersole
* @author Gavin King
*/
public abstract class AbstractNamedQueryMemento implements NamedQueryMemento {
private final String name;
private final @Nullable Class<?> resultType;

private final Boolean cacheable;
private final String cacheRegion;
Expand All @@ -37,6 +40,7 @@ public abstract class AbstractNamedQueryMemento implements NamedQueryMemento {

protected AbstractNamedQueryMemento(
String name,
@Nullable Class<?> resultType,
Boolean cacheable,
String cacheRegion,
CacheMode cacheMode,
Expand All @@ -47,6 +51,7 @@ protected AbstractNamedQueryMemento(
String comment,
Map<String, Object> hints) {
this.name = name;
this.resultType = resultType;
this.cacheable = cacheable;
this.cacheRegion = cacheRegion;
this.cacheMode = cacheMode;
Expand All @@ -63,6 +68,10 @@ public String getRegistrationName() {
return name;
}

public @Nullable Class<?> getResultType() {
return resultType;
}

@Override
public Boolean getCacheable() {
return cacheable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class NamedNativeQueryMementoImpl extends AbstractNamedQueryMemento imple

public NamedNativeQueryMementoImpl(
String name,
Class<?> resultClass,
String sqlString,
String originalSqlString,
String resultSetMappingName,
Expand All @@ -56,6 +57,7 @@ public NamedNativeQueryMementoImpl(
Map<String,Object> hints) {
super(
name,
resultClass,
cacheable,
cacheRegion,
cacheMode,
Expand Down Expand Up @@ -123,6 +125,7 @@ public Integer getMaxResults() {
public NamedNativeQueryMemento makeCopy(String name) {
return new NamedNativeQueryMementoImpl(
name,
getResultType(),
sqlString,
originalSqlString,
resultSetMappingName,
Expand All @@ -149,7 +152,8 @@ public void validate(QueryEngine queryEngine) {

@Override
public <T> NativeQueryImplementor<T> toQuery(SharedSessionContractImplementor session) {
return new NativeQueryImpl<>( this, session );
//noinspection unchecked
return new NativeQueryImpl<>( this, (Class<T>) getResultType(), session );
}

@Override
Expand Down
Loading
Loading