HHH-15653 Named Native Query cannot be registered/used with named parameters
This commit is contained in:
parent
0d2e39314f
commit
cc570da296
|
@ -89,6 +89,7 @@ public class NamedNativeQueryDefinitionImpl extends AbstractNamedQueryDefinition
|
||||||
return new NamedNativeQueryMementoImpl(
|
return new NamedNativeQueryMementoImpl(
|
||||||
getRegistrationName(),
|
getRegistrationName(),
|
||||||
sqlString,
|
sqlString,
|
||||||
|
sqlString,
|
||||||
resultSetMappingName,
|
resultSetMappingName,
|
||||||
isNotEmpty( resultSetMappingClassName )
|
isNotEmpty( resultSetMappingClassName )
|
||||||
? factory.getServiceRegistry().getService( ClassLoaderService.class )
|
? factory.getServiceRegistry().getService( ClassLoaderService.class )
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.hibernate.query.sql.spi.NativeQueryImplementor;
|
||||||
*/
|
*/
|
||||||
public class NamedNativeQueryMementoImpl extends AbstractNamedQueryMemento implements NamedNativeQueryMemento {
|
public class NamedNativeQueryMementoImpl extends AbstractNamedQueryMemento implements NamedNativeQueryMemento {
|
||||||
private final String sqlString;
|
private final String sqlString;
|
||||||
|
private final String originalSqlString;
|
||||||
|
|
||||||
private final String resultSetMappingName;
|
private final String resultSetMappingName;
|
||||||
private final Class<?> resultSetMappingClass;
|
private final Class<?> resultSetMappingClass;
|
||||||
|
@ -38,6 +39,7 @@ public class NamedNativeQueryMementoImpl extends AbstractNamedQueryMemento imple
|
||||||
public NamedNativeQueryMementoImpl(
|
public NamedNativeQueryMementoImpl(
|
||||||
String name,
|
String name,
|
||||||
String sqlString,
|
String sqlString,
|
||||||
|
String originalSqlString,
|
||||||
String resultSetMappingName,
|
String resultSetMappingName,
|
||||||
Class<?> resultSetMappingClass,
|
Class<?> resultSetMappingClass,
|
||||||
Set<String> querySpaces,
|
Set<String> querySpaces,
|
||||||
|
@ -65,6 +67,7 @@ public class NamedNativeQueryMementoImpl extends AbstractNamedQueryMemento imple
|
||||||
hints
|
hints
|
||||||
);
|
);
|
||||||
this.sqlString = sqlString;
|
this.sqlString = sqlString;
|
||||||
|
this.originalSqlString = originalSqlString;
|
||||||
this.resultSetMappingName = resultSetMappingName == null || resultSetMappingName.isEmpty()
|
this.resultSetMappingName = resultSetMappingName == null || resultSetMappingName.isEmpty()
|
||||||
? null
|
? null
|
||||||
: resultSetMappingName;
|
: resultSetMappingName;
|
||||||
|
@ -91,6 +94,11 @@ public class NamedNativeQueryMementoImpl extends AbstractNamedQueryMemento imple
|
||||||
return sqlString;
|
return sqlString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getOriginalSqlString() {
|
||||||
|
return originalSqlString;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getResultMappingName() {
|
public String getResultMappingName() {
|
||||||
return resultSetMappingName;
|
return resultSetMappingName;
|
||||||
|
@ -116,6 +124,7 @@ public class NamedNativeQueryMementoImpl extends AbstractNamedQueryMemento imple
|
||||||
return new NamedNativeQueryMementoImpl(
|
return new NamedNativeQueryMementoImpl(
|
||||||
name,
|
name,
|
||||||
sqlString,
|
sqlString,
|
||||||
|
originalSqlString,
|
||||||
resultSetMappingName,
|
resultSetMappingName,
|
||||||
resultSetMappingClass,
|
resultSetMappingClass,
|
||||||
querySpaces,
|
querySpaces,
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class NativeQueryImpl<R>
|
||||||
extends AbstractQuery<R>
|
extends AbstractQuery<R>
|
||||||
implements NativeQueryImplementor<R>, DomainQueryExecutionContext, ResultSetMappingResolutionContext {
|
implements NativeQueryImplementor<R>, DomainQueryExecutionContext, ResultSetMappingResolutionContext {
|
||||||
private final String sqlString;
|
private final String sqlString;
|
||||||
|
private final String originalSqlString;
|
||||||
private final ParameterMetadataImplementor parameterMetadata;
|
private final ParameterMetadataImplementor parameterMetadata;
|
||||||
private final List<ParameterOccurrence> parameterOccurrences;
|
private final List<ParameterOccurrence> parameterOccurrences;
|
||||||
private final QueryParameterBindings parameterBindings;
|
private final QueryParameterBindings parameterBindings;
|
||||||
|
@ -186,8 +186,12 @@ public class NativeQueryImpl<R>
|
||||||
SharedSessionContractImplementor session) {
|
SharedSessionContractImplementor session) {
|
||||||
super( session );
|
super( session );
|
||||||
|
|
||||||
final String mementoSqlString = memento.getSqlString();
|
this.originalSqlString = memento.getOriginalSqlString();
|
||||||
final ParameterInterpretation parameterInterpretation = resolveParameterInterpretation( mementoSqlString, session );
|
|
||||||
|
final ParameterInterpretation parameterInterpretation = resolveParameterInterpretation(
|
||||||
|
originalSqlString,
|
||||||
|
session
|
||||||
|
);
|
||||||
|
|
||||||
this.sqlString = parameterInterpretation.getAdjustedSqlString();
|
this.sqlString = parameterInterpretation.getAdjustedSqlString();
|
||||||
this.parameterMetadata = parameterInterpretation.toParameterMetadata( session );
|
this.parameterMetadata = parameterInterpretation.toParameterMetadata( session );
|
||||||
|
@ -322,6 +326,7 @@ public class NativeQueryImpl<R>
|
||||||
|
|
||||||
final ParameterInterpretation parameterInterpretation = resolveParameterInterpretation( sqlString, session );
|
final ParameterInterpretation parameterInterpretation = resolveParameterInterpretation( sqlString, session );
|
||||||
|
|
||||||
|
this.originalSqlString = sqlString;
|
||||||
this.sqlString = parameterInterpretation.getAdjustedSqlString();
|
this.sqlString = parameterInterpretation.getAdjustedSqlString();
|
||||||
this.parameterMetadata = parameterInterpretation.toParameterMetadata( session );
|
this.parameterMetadata = parameterInterpretation.toParameterMetadata( session );
|
||||||
this.parameterOccurrences = parameterInterpretation.getOrderedParameterOccurrences();
|
this.parameterOccurrences = parameterInterpretation.getOrderedParameterOccurrences();
|
||||||
|
@ -383,7 +388,7 @@ public class NativeQueryImpl<R>
|
||||||
this.querySpaces = new HashSet<>();
|
this.querySpaces = new HashSet<>();
|
||||||
|
|
||||||
final ParameterInterpretation parameterInterpretation = resolveParameterInterpretation( sqlString, session );
|
final ParameterInterpretation parameterInterpretation = resolveParameterInterpretation( sqlString, session );
|
||||||
|
this.originalSqlString = sqlString;
|
||||||
this.sqlString = parameterInterpretation.getAdjustedSqlString();
|
this.sqlString = parameterInterpretation.getAdjustedSqlString();
|
||||||
this.parameterMetadata = parameterInterpretation.toParameterMetadata( session );
|
this.parameterMetadata = parameterInterpretation.toParameterMetadata( session );
|
||||||
this.parameterOccurrences = parameterInterpretation.getOrderedParameterOccurrences();
|
this.parameterOccurrences = parameterInterpretation.getOrderedParameterOccurrences();
|
||||||
|
@ -455,6 +460,7 @@ public class NativeQueryImpl<R>
|
||||||
return new NamedNativeQueryMementoImpl(
|
return new NamedNativeQueryMementoImpl(
|
||||||
name,
|
name,
|
||||||
sqlString,
|
sqlString,
|
||||||
|
originalSqlString,
|
||||||
resultSetMapping.getMappingIdentifier(),
|
resultSetMapping.getMappingIdentifier(),
|
||||||
null,
|
null,
|
||||||
querySpaces,
|
querySpaces,
|
||||||
|
|
|
@ -29,6 +29,10 @@ public interface NamedNativeQueryMemento extends NamedQueryMemento {
|
||||||
*/
|
*/
|
||||||
String getSqlString();
|
String getSqlString();
|
||||||
|
|
||||||
|
default String getOriginalSqlString(){
|
||||||
|
return getSqlString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The affected query spaces.
|
* The affected query spaces.
|
||||||
*/
|
*/
|
||||||
|
@ -132,6 +136,7 @@ public interface NamedNativeQueryMemento extends NamedQueryMemento {
|
||||||
return new NamedNativeQueryMementoImpl(
|
return new NamedNativeQueryMementoImpl(
|
||||||
name,
|
name,
|
||||||
queryString,
|
queryString,
|
||||||
|
queryString,
|
||||||
resultSetMappingName,
|
resultSetMappingName,
|
||||||
sessionFactory.getServiceRegistry()
|
sessionFactory.getServiceRegistry()
|
||||||
.getService( ClassLoaderService.class )
|
.getService( ClassLoaderService.class )
|
||||||
|
|
Loading…
Reference in New Issue