Parameter value did not match expected type even thought it matches

I am getting the exception below.
org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [com.x.y.z.domain.prefix.OrderPrefix@842cfa72] did not match expected type [java.util.List (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [com.x.y.z.domain.prefix.OrderPrefix@842cfa72] did not match expected type [java.util.List (n/a)]

My DAO is looking like this

public Entity{
@Convert(converter = PrefixToStringConverter.class)
    private List<Prefix> prefixes;
       .... getters, setters.

Basically I am converting Prefix list to string and writing to database as a string in a column. I can save successfully while I am using Spring Data JPA’s CrudRepository. However I have a custom update query which takes fields and manually updates and it looks like this.

    @Query("update Entity per set per.programme = :#{#rule.programme}, " +
            "per.rule = :#{#rule.rule}, " +
            "per.commission = :#{#rule.commission}, " +
            "per.condition = :#{#rule.condition}, " +
            "per.description = :#{#rule.description}, " +
            "per.prefixes = :#{#rule.prefixes} " +
            "where per.perId = :#{#rule.perId}")
    int update(Entity rule);

After I pass a valid Entity object to this class, I am quite sure that I am passing a List object to prefixes field. However I keep getting the same exception over and over again. Actually when I turn the rollback off, i can see that it updates the result, however throws exception after execution.

Could you guys point me out where the mistake is? Thank you!

I think this might be a Spring Data issue.

It’s only a Hibernate issue if you can replicate it with this test case template.

1 Like

Thanks for your reply! I also want to confirm that my implementation logic doesn’t sound broken. Prefix is a custom interface and I am able to confirm that Converter class is able to de/serialise JSON to List and vice versa but it fails to do so with custom query. I also tried to use Spring Data’s entity manager object to build same query I built with @Query but it failed. I will try to use the test case that you provide to figure out whether that’s a Spring issue or not. Thank you!

I can confirm that I managed to create the same error with a different exception type using the test case you provided. This time I used entitymanager.createUpdate() and got this one. Thank you.

java.lang.IllegalArgumentException: Parameter value [com.x.y.z.PreOrderPrefix@842cfa72] did not match expected type [java.util.List (n/a)]

1 Like

Can you share the GitHub repository with us so we can take a look?

It is a closed source software but i will create the stripped sample to demonstrate. Thanks

You already created the GitHub repository. Just add a zip with the downloaded copy of the Hibernate-5 folder.

Did anyone found the resolution of this problem ?


Is there a Jira track number?

1 Like

I’m still getting this issue with spring data 2.4.2 (hibernate 5.4.27.Final)
Does it have a fix?

This will simply not work right now. We might be able to fix this for Hibernate 6.0 but right now, we simply interpret any collection as mutli-valued parameter value, because we don’t know for sure if a parameter allows a multi-valued value. As a workaround, you can bind the string.