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