diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedNativeQueryDefinitionImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedNativeQueryDefinitionImpl.java index 7a3aca5136..ff524bf287 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedNativeQueryDefinitionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/NamedNativeQueryDefinitionImpl.java @@ -89,6 +89,7 @@ public class NamedNativeQueryDefinitionImpl extends AbstractNamedQueryDefinition return new NamedNativeQueryMementoImpl( getRegistrationName(), sqlString, + sqlString, resultSetMappingName, isNotEmpty( resultSetMappingClassName ) ? factory.getServiceRegistry().getService( ClassLoaderService.class ) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NamedNativeQueryMementoImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NamedNativeQueryMementoImpl.java index 7e6c077ca9..8ba29214b4 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NamedNativeQueryMementoImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NamedNativeQueryMementoImpl.java @@ -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 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, diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java index 0d9b0d004f..c245187529 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java @@ -111,7 +111,7 @@ public class NativeQueryImpl extends AbstractQuery implements NativeQueryImplementor, DomainQueryExecutionContext, ResultSetMappingResolutionContext { private final String sqlString; - + private final String originalSqlString; private final ParameterMetadataImplementor parameterMetadata; private final List parameterOccurrences; private final QueryParameterBindings parameterBindings; @@ -186,8 +186,12 @@ public class NativeQueryImpl 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 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 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 return new NamedNativeQueryMementoImpl( name, sqlString, + originalSqlString, resultSetMapping.getMappingIdentifier(), null, querySpaces, diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NamedNativeQueryMemento.java b/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NamedNativeQueryMemento.java index 54bcc670c2..9ba09a7a0f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NamedNativeQueryMemento.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NamedNativeQueryMemento.java @@ -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 )