Skip to content

Conversation

thomasdarimont
Copy link
Contributor

In order to support query methods with array-typed parameters (e.g. parameters passed in as varargs) correctly we have to convert such an array into a collection. Previously we passed those parameters as is which led to Exceptions in EclipseLink and Hibernate, e.g. Hibernate: IllegalArgumentException: Encountered array-valued parameter binding, but was expecting [java.lang.Integer].

In order to support query methods with array-typed parameters (e.g. parameters passed in as varargs) correctly we have to convert such an array into a collection. Previously we passed those parameters as is which led to Exceptions in EclipseLink and Hibernate, e.g. Hibernate: IllegalArgumentException: Encountered array-valued parameter binding, but was expecting [java.lang.Integer].
odrotbohm added a commit that referenced this pull request Oct 25, 2013
Simplified implementation of ParameterBinder.convertToCollectionIfNecessary(…).

Added a simpler test case for plain query execution and ignored that for EclipseLink and OpenJpa as it fails with both the EclipseLink and OpenJpa versions we currently rely on. See the ignored test cases for links to bug reports.

Original pull request: #45.
@thomasdarimont
Copy link
Contributor Author

This went into SD JPA 1.5.0 M1.

@maggmanu77
Copy link

This seems to have introduced a problem when dealing with input host variables being supplied as plain arrays. Example: Consider a byte array as input parameter for a field on a table.

The function org.springframework.data.jpa.repository.query.ParameterBinder::convertArrayToCollectionIfNecessary converts the input byte array to an ArrayList collection. But the parameter information in org.springframework.data.jpa.repository.query.ParameterBinder::bind(Query query, JpaParameter parameter, Object value, int position) - still points to the type byte array. Starting with Hibernate Implementation of JPA 2.1 (Hibernate version 4.3.1) the validators (org.hibernate.jpa.spi.BaseQueryImpl::validateBinding(Class parameterType, Object bind, TemporalType temporalType) will compare the supplied type and actual type of the host variable passed and will reject the query with an exception.

Example Trace:
java.lang.IllegalArgumentException: Parameter value element [120] did not match expected type [[B (n/a)]
at org.hibernate.jpa.spi.BaseQueryImpl.validateCollectionValuedParameterBinding(BaseQueryImpl.java:908)

@thomasdarimont
Copy link
Contributor Author

Hi maggmanu77,

we've created https://jira.springsource.org/browse/DATAJPA-461 to track this issue.
We should continue the discussion there :)

Would you mind providing some context (e.g. the query / update that you wanted to define etc.)? to the issue?

Cheers,
Thomas

@maggmanu77
Copy link

Thanks Thomas,
Here is the maven test case for this bug.
https://github.com/maggmanu77/spring-data-jpa2-1bugreport.git

Added this test case info to JIRA as well.

thanks, manu,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants