java.lang.IllegalArgumentException: Parameter value [1] did not match expected type [com.mach.msp.qos.error_exclusion.model.B (n/a)]

Spring JIRA | Adam Michalik | 3 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Given following setup (equals, hashcode and constructors omitted): {code:java} @Entity @IdClass(A.Id.class) public class A { @javax.persistence.Id private Long basicId; @javax.persistence.Id @ManyToOne private B b; public static class Id implements Serializable { private Long basicId; private Long b; } @Entity public class B { @Id private Long id; } public interface ARepository extends Repository<A, A.Id> { public boolean exists(A.Id id); } {code} the following test fails with an error: {code:java} @Test public void exclusion_exists() { B b = new B(1L); em.persist(b); em.persist(new A(2L, b)); boolean exists = repository.exists(new A.Id(2L, 1L)); assertThat(exists).isTrue(); } {code} The error is (Spring Data 1.4.3) {code} java.lang.IllegalArgumentException: Parameter value [1] did not match expected type [com.mach.msp.qos.error_exclusion.model.B (n/a)] at org.hibernate.ejb.AbstractQueryImpl.validateBinding(AbstractQueryImpl.java:382) at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:356) at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:347) at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:373) at org.springframework.data.jpa.repository.support.SimpleJpaRepository.exists(SimpleJpaRepository.java:234) ... {code} I checked also 1.4.5 and 1.5.2 and both fail in the same way. It seems to me that Spring Data does not realize that when a relationship is used in a composite key, the relationship is marked with @Id, but in the IdClass only the key of the relationship's other side must be used (cf. JPA 2.0 spec: 2.4.1 Primary Keys Corresponding to Derived Identities). Running {{repository.findOne()}} works fine under the same circumstances.

    Spring JIRA | 3 years ago | Adam Michalik
    java.lang.IllegalArgumentException: Parameter value [1] did not match expected type [com.mach.msp.qos.error_exclusion.model.B (n/a)]
  2. 0

    Given following setup (equals, hashcode and constructors omitted): {code:java} @Entity @IdClass(A.Id.class) public class A { @javax.persistence.Id private Long basicId; @javax.persistence.Id @ManyToOne private B b; public static class Id implements Serializable { private Long basicId; private Long b; } @Entity public class B { @Id private Long id; } public interface ARepository extends Repository<A, A.Id> { public boolean exists(A.Id id); } {code} the following test fails with an error: {code:java} @Test public void exclusion_exists() { B b = new B(1L); em.persist(b); em.persist(new A(2L, b)); boolean exists = repository.exists(new A.Id(2L, 1L)); assertThat(exists).isTrue(); } {code} The error is (Spring Data 1.4.3) {code} java.lang.IllegalArgumentException: Parameter value [1] did not match expected type [com.mach.msp.qos.error_exclusion.model.B (n/a)] at org.hibernate.ejb.AbstractQueryImpl.validateBinding(AbstractQueryImpl.java:382) at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:356) at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:347) at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:373) at org.springframework.data.jpa.repository.support.SimpleJpaRepository.exists(SimpleJpaRepository.java:234) ... {code} I checked also 1.4.5 and 1.5.2 and both fail in the same way. It seems to me that Spring Data does not realize that when a relationship is used in a composite key, the relationship is marked with @Id, but in the IdClass only the key of the relationship's other side must be used (cf. JPA 2.0 spec: 2.4.1 Primary Keys Corresponding to Derived Identities). Running {{repository.findOne()}} works fine under the same circumstances.

    Spring JIRA | 3 years ago | Adam Michalik
    java.lang.IllegalArgumentException: Parameter value [1] did not match expected type [com.mach.msp.qos.error_exclusion.model.B (n/a)]
  3. 0

    QueryDsl-JPA SUM on Integer field - Parameter value did not match expected type

    Stack Overflow | 4 years ago | Arthur canardo'
    java.lang.IllegalArgumentException: Parameter value [0] did not match expected type [java.lang.Long]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    QueryDSL Creating query with @Embedded column

    GitHub | 2 years ago | miroslav24
    java.lang.IllegalArgumentException: Parameter value [Jo%] did not match expected type [com.package.CustomerName]
  6. 0

    Exception with BigDecimal constant in JPAQuery creation

    GitHub | 4 years ago | steeltomato
    java.lang.IllegalArgumentException: Parameter value [1.0] did not match expected type [java.math.BigDecimal]

    3 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      Parameter value [1] did not match expected type [com.mach.msp.qos.error_exclusion.model.B (n/a)]

      at org.hibernate.ejb.AbstractQueryImpl.validateBinding()
    2. Hibernate EJB
      QueryImpl.setParameter
      1. org.hibernate.ejb.AbstractQueryImpl.validateBinding(AbstractQueryImpl.java:382)
      2. org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:356)
      3. org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:347)
      4. org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:373)
      4 frames
    3. Spring Data JPA
      SimpleJpaRepository.exists
      1. org.springframework.data.jpa.repository.support.SimpleJpaRepository.exists(SimpleJpaRepository.java:234)
      1 frame