diff --git a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/HQLQueryPlan.java b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/HQLQueryPlan.java index 113de2d970..4a9054b3dd 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/HQLQueryPlan.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/HQLQueryPlan.java @@ -151,7 +151,7 @@ public class HQLQueryPlan implements Serializable { } public ParameterMetadataImpl getParameterMetadata() { - return parameterMetadata; + return parameterMetadata.getOrdinalParametersZeroBasedCopy(); } public ReturnMetadata getReturnMetadata() { diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index 05842181fc..327516c8a2 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -727,7 +727,9 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont @Override public QueryImplementor createNamedQuery(String name) { - return buildQueryFromName( name, null ); + final QueryImplementor query = buildQueryFromName( name, null ); + query.getParameterMetadata().setOrdinalParametersZeroBased( false ); + return query; } protected QueryImplementor buildQueryFromName(String name, Class resultType) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/ParameterMetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/ParameterMetadataImpl.java index f560ec2e82..c913ceceeb 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/ParameterMetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/ParameterMetadataImpl.java @@ -33,6 +33,14 @@ public class ParameterMetadataImpl implements ParameterMetadata { private final Map namedDescriptorMap; private boolean isOrdinalParametersZeroBased = true; + private ParameterMetadataImpl( + OrdinalParameterDescriptor[] ordinalDescriptors, + Map namedDescriptorMap, boolean isOrdinalParametersZeroBased) { + this.ordinalDescriptors = ordinalDescriptors; + this.namedDescriptorMap = namedDescriptorMap; + this.isOrdinalParametersZeroBased = isOrdinalParametersZeroBased; + } + /** * Instantiates a ParameterMetadata container. * @@ -252,4 +260,12 @@ public class ParameterMetadataImpl implements ParameterMetadata { public void setOrdinalParametersZeroBased(boolean isZeroBased) { this.isOrdinalParametersZeroBased = isZeroBased; } + + public ParameterMetadataImpl getOrdinalParametersZeroBasedCopy() { + return new ParameterMetadataImpl( + this.ordinalDescriptors, + this.namedDescriptorMap, + true + ); + } }