Search in sources :

Example 1 with QueryParameterException

use of org.hibernate.QueryParameterException in project hibernate-orm by hibernate.

the class QueryParameterBindingsImpl method getBinding.

public QueryParameterBinding getBinding(int position) {
    int positionAdjustment = 0;
    if (!parameterMetadata.isOrdinalParametersZeroBased()) {
        positionAdjustment = -1;
    }
    QueryParameterBinding binding = null;
    if (parameterMetadata != null) {
        if (!parameterMetadata.hasPositionalParameters()) {
            // no positional parameters, assume jpa named.
            binding = locateBinding(Integer.toString(position));
        } else {
            try {
                binding = positionalParameterBindings.get(position + positionAdjustment);
                if (binding == null) {
                    binding = makeBinding(parameterMetadata.getQueryParameter(position));
                    positionalParameterBindings.put(position + positionAdjustment, binding);
                }
            } catch (QueryParameterException e) {
            // treat this as null binding
            }
        }
    }
    if (binding == null) {
        throw new IllegalArgumentException("Unknown parameter position: " + position);
    }
    return binding;
}
Also used : QueryParameterException(org.hibernate.QueryParameterException) QueryParameterBinding(org.hibernate.query.spi.QueryParameterBinding)

Example 2 with QueryParameterException

use of org.hibernate.QueryParameterException in project hibernate-orm by hibernate.

the class AbstractProducedQuery method getParameterValue.

@Override
public Object getParameterValue(String name) {
    getProducer().checkOpen(false);
    final QueryParameterBinding binding;
    try {
        binding = getQueryParameterBindings().getBinding(name);
    } catch (QueryParameterException e) {
        throw new IllegalArgumentException("Could not resolve parameter by name - " + name, e);
    }
    LOGGER.debugf("Checking whether named parameter [%s] is bound : %s", name, binding.isBound());
    if (!binding.isBound()) {
        throw new IllegalStateException("Parameter value not yet bound : " + name);
    }
    return binding.getBindValue();
}
Also used : QueryParameterException(org.hibernate.QueryParameterException) QueryParameterBinding(org.hibernate.query.spi.QueryParameterBinding)

Example 3 with QueryParameterException

use of org.hibernate.QueryParameterException in project hibernate-orm by hibernate.

the class AbstractProducedQuery method getParameterValue.

@Override
public Object getParameterValue(int position) {
    getProducer().checkOpen(false);
    final QueryParameterBinding binding;
    try {
        binding = getQueryParameterBindings().getBinding(position);
    } catch (QueryParameterException e) {
        throw new IllegalArgumentException("Could not resolve parameter by position - " + position, e);
    }
    LOGGER.debugf("Checking whether positional  parameter [%s] is bound : %s", (Integer) position, (Boolean) binding.isBound());
    if (!binding.isBound()) {
        throw new IllegalStateException("Parameter value not yet bound : " + position);
    }
    return binding.getBindValue();
}
Also used : QueryParameterException(org.hibernate.QueryParameterException) QueryParameterBinding(org.hibernate.query.spi.QueryParameterBinding)

Aggregations

QueryParameterException (org.hibernate.QueryParameterException)3 QueryParameterBinding (org.hibernate.query.spi.QueryParameterBinding)3