HHH-15895 IllegalArgumentException: Cannot create binding for parameter referencen with criteria builder
This commit is contained in:
parent
e1779a7662
commit
e65ded7a21
|
@ -43,37 +43,8 @@ public class DomainParameterXref {
|
|||
// references (one for each occurrence of `:param`) both of which map to
|
||||
// the same QueryParameter.
|
||||
final Map<SqmParameter, QueryParameterImplementor<?>> xrefMap = new TreeMap<>(
|
||||
(o1, o2) -> {
|
||||
if ( o1 instanceof SqmNamedParameter ) {
|
||||
final SqmNamedParameter<?> one = (SqmNamedParameter<?>) o1;
|
||||
return o2 instanceof SqmNamedParameter<?>
|
||||
? one.getName().compareTo( ((SqmNamedParameter<?>) o2).getName() )
|
||||
: -1;
|
||||
}
|
||||
else if ( o1 instanceof SqmPositionalParameter ) {
|
||||
final SqmPositionalParameter<?> one = (SqmPositionalParameter<?>) o1;
|
||||
return o2 instanceof SqmPositionalParameter<?>
|
||||
? one.getPosition().compareTo( ( (SqmPositionalParameter<?>) o2 ).getPosition() )
|
||||
: 1;
|
||||
}
|
||||
else if ( o1 instanceof SqmJpaCriteriaParameterWrapper
|
||||
&& o2 instanceof SqmJpaCriteriaParameterWrapper ) {
|
||||
// final SqmJpaCriteriaParameterWrapper wrapper1 = (SqmJpaCriteriaParameterWrapper) o1;
|
||||
// final SqmJpaCriteriaParameterWrapper wrapper2 = (SqmJpaCriteriaParameterWrapper) o2;
|
||||
// if ( wrapper1.getJpaCriteriaParameter() == wrapper2.getJpaCriteriaParameter() ) {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// if ( o1.getName() != null ) {
|
||||
// return o1.getName().compareTo( o2.getName() );
|
||||
// }
|
||||
// else {
|
||||
return Integer.compare( o1.hashCode(), o2.hashCode() );
|
||||
// }
|
||||
}
|
||||
|
||||
throw new HibernateException( "Unexpected SqmParameter type for comparison : " + o1 + " & " + o2 );
|
||||
}
|
||||
(o1, o2) ->
|
||||
o1.compare( o2 )
|
||||
);
|
||||
|
||||
final SqmStatement.ParameterResolutions parameterResolutions = sqmStatement.resolveParameters();
|
||||
|
|
|
@ -164,4 +164,11 @@ public class JpaCriteriaParameter<T>
|
|||
}
|
||||
return Objects.hash( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(SqmParameter anotherParameter) {
|
||||
return anotherParameter instanceof JpaCriteriaParameter ?
|
||||
Integer.compare( hashCode(), anotherParameter.hashCode() )
|
||||
: 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,6 +123,13 @@ public class SqmJpaCriteriaParameterWrapper<T>
|
|||
jpaCriteriaParameter.appendHqlString( sb );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(SqmParameter anotherParameter) {
|
||||
return anotherParameter instanceof SqmJpaCriteriaParameterWrapper ?
|
||||
getJpaCriteriaParameter().compare( ( (SqmJpaCriteriaParameterWrapper<?>) anotherParameter ).getJpaCriteriaParameter() )
|
||||
: 1;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public Expression toSqlExpression(
|
||||
// Clause clause,
|
||||
|
|
|
@ -81,4 +81,11 @@ public class SqmNamedParameter<T> extends AbstractSqmParameter<T> {
|
|||
sb.append( ':' );
|
||||
sb.append( getName() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(SqmParameter anotherParameter) {
|
||||
return anotherParameter instanceof SqmNamedParameter<?>
|
||||
? getName().compareTo( ( (SqmNamedParameter<?>) anotherParameter ).getName() )
|
||||
: -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.query.sqm.tree.expression;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.query.BindableType;
|
||||
import org.hibernate.query.criteria.JpaParameterExpression;
|
||||
import org.hibernate.query.sqm.SqmExpressible;
|
||||
|
@ -74,4 +75,24 @@ public interface SqmParameter<T> extends SqmExpression<T>, JpaParameterExpressio
|
|||
|
||||
@Override
|
||||
SqmParameter<T> copy(SqmCopyContext context);
|
||||
|
||||
default int compare(SqmParameter anotherParameter) {
|
||||
if ( this instanceof SqmNamedParameter ) {
|
||||
final SqmNamedParameter<?> one = (SqmNamedParameter<?>) this;
|
||||
return anotherParameter instanceof SqmNamedParameter<?>
|
||||
? one.getName().compareTo( ( (SqmNamedParameter<?>) anotherParameter ).getName() )
|
||||
: -1;
|
||||
}
|
||||
else if ( this instanceof SqmPositionalParameter ) {
|
||||
final SqmPositionalParameter<?> one = (SqmPositionalParameter<?>) this;
|
||||
return anotherParameter instanceof SqmPositionalParameter<?>
|
||||
? one.getPosition().compareTo( ( (SqmPositionalParameter<?>) anotherParameter ).getPosition() )
|
||||
: 1;
|
||||
}
|
||||
else if ( anotherParameter instanceof SqmJpaCriteriaParameterWrapper
|
||||
&& anotherParameter instanceof SqmJpaCriteriaParameterWrapper ) {
|
||||
return Integer.compare( this.hashCode(), anotherParameter.hashCode() );
|
||||
}
|
||||
throw new HibernateException( "Unexpected SqmParameter type for comparison : " + this + " & " + anotherParameter );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,4 +85,10 @@ public class SqmPositionalParameter<T> extends AbstractSqmParameter<T> {
|
|||
sb.append( getPosition() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(SqmParameter anotherParameter) {
|
||||
return anotherParameter instanceof SqmPositionalParameter<?>
|
||||
? getPosition().compareTo( ( (SqmPositionalParameter<?>) anotherParameter ).getPosition() )
|
||||
: 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.query.sqm.tree.expression;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.hibernate.query.BindableType;
|
||||
import org.hibernate.query.sqm.NodeBuilder;
|
||||
import org.hibernate.query.sqm.tree.SqmCopyContext;
|
||||
|
@ -62,4 +64,12 @@ public class ValueBindJpaCriteriaParameter<T> extends JpaCriteriaParameter<T>{
|
|||
public int hashCode() {
|
||||
return System.identityHashCode( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(SqmParameter anotherParameter) {
|
||||
if ( this == anotherParameter ) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue