java.lang.IllegalArgumentException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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.
    via by Adam Michalik,
  • 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.
    via by Adam Michalik,
  • JPA could not locate named parameter
    via Stack Overflow by BillR
    ,
    • 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)

    Users with the same issue

    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,