From 5cb5b68f9c9b7a37fd78cd6c637724862d18c725 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 27 Jun 2016 16:03:41 +0200 Subject: [PATCH] HHH-10893 - Fix Reusing Query but changing collection parameters returns wrong result --- .../query/spi/NamedParameterDescriptor.java | 18 ++++++++++++++++++ .../internal/QueryParameterBindingsImpl.java | 4 +--- .../internal/QueryParameterNamedImpl.java | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/NamedParameterDescriptor.java b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/NamedParameterDescriptor.java index 91997b55f0..4b5cc863c8 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/query/spi/NamedParameterDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/query/spi/NamedParameterDescriptor.java @@ -81,4 +81,22 @@ public class NamedParameterDescriptor implements QueryParameter { public Type getType() { return expectedType; } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + NamedParameterDescriptor that = (NamedParameterDescriptor) o; + return getName().equals( that.getName() ); + } + + @Override + public int hashCode() { + return getName().hashCode(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java index 4a6c436a96..4a4533efbd 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterBindingsImpl.java @@ -586,9 +586,7 @@ public class QueryParameterBindingsImpl implements QueryParameterBindings { ); final QueryParameterBinding syntheticBinding = makeBinding( entry.getValue().getBindType() ); syntheticBinding.setBindValue( bindValue ); - if ( parameterBindingMap.put( syntheticParam, syntheticBinding ) != null ) { - throw new HibernateException( "Repeated usage of synthetic parameter name [" + syntheticName + "] while expanding list parameter." ); - } + parameterBindingMap.put( syntheticParam, syntheticBinding ); i++; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterNamedImpl.java b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterNamedImpl.java index 102b91fa40..f31b6e51ae 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterNamedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/QueryParameterNamedImpl.java @@ -49,4 +49,22 @@ public class QueryParameterNamedImpl extends QueryParameterImpl implements public boolean isJpaPositionalParameter() { return jpaStyle; } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + QueryParameterNamedImpl that = (QueryParameterNamedImpl) o; + return getName().equals( that.getName() ); + } + + @Override + public int hashCode() { + return getName().hashCode(); + } }