java.lang.IllegalArgumentException: Parameter value [ROLE_2] was not matching type [java.util.Set]

Hibernate JIRA | Koen Molkenboer | 6 years ago
  1. 0

    The situation is as follow: I have an User class which has a collection of elements which is a Set of Role enum values and I want to search for users which have one of more roles. I want to use the CriteriaBuilder, because I have a search form with a lot of fields which are optional. The User class: @Entity @Table(name = "USERS") @Access(AccessType.FIELD) public class User implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "ID") private Long id; @Column(name = "USERNAME", unique = true, nullable = false, length = 128) private String username; @ElementCollection @Enumerated(EnumType.STRING) @Column(name = "ROLE") @CollectionTable(name = "USER_ROLES", joinColumns = @JoinColumn(name = "USER_ID")) private Set<Role> roles = new HashSet<Role>(); ... } The enum Role: public enum Role { ROLE_1, ROLE_2, ROLE_3; } Creating the query with the CriteriaBuilder Set<Role> roles = new HashSet<Role>(); roles.add(Role.ROLE_1); roles.add(Role.ROLE_2); CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<User> criteriaQuery = criteriaBuilder.createQuery(User.class); Root<User> root = criteriaQuery.from(User.class); criteriaQuery.where(root.join("roles").in(roles)); TypedQuery<User> query = entityManager.createQuery(criteriaQuery); query.getResultList(); This is the exception: java.lang.IllegalArgumentException: Parameter value [ROLE_2] was not matching type [java.util.Set] at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:360) at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:359) at org.hibernate.ejb.criteria.CriteriaQueryCompiler$1$1.bind(CriteriaQueryCompiler.java:194) at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:247) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:437) ... This all works with OpenJPA 2.0.0

    Hibernate JIRA | 6 years ago | Koen Molkenboer
    java.lang.IllegalArgumentException: Parameter value [ROLE_2] was not matching type [java.util.Set]
  2. 0

    The situation is as follow: I have an User class which has a collection of elements which is a Set of Role enum values and I want to search for users which have one of more roles. I want to use the CriteriaBuilder, because I have a search form with a lot of fields which are optional. The User class: @Entity @Table(name = "USERS") @Access(AccessType.FIELD) public class User implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "ID") private Long id; @Column(name = "USERNAME", unique = true, nullable = false, length = 128) private String username; @ElementCollection @Enumerated(EnumType.STRING) @Column(name = "ROLE") @CollectionTable(name = "USER_ROLES", joinColumns = @JoinColumn(name = "USER_ID")) private Set<Role> roles = new HashSet<Role>(); ... } The enum Role: public enum Role { ROLE_1, ROLE_2, ROLE_3; } Creating the query with the CriteriaBuilder Set<Role> roles = new HashSet<Role>(); roles.add(Role.ROLE_1); roles.add(Role.ROLE_2); CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<User> criteriaQuery = criteriaBuilder.createQuery(User.class); Root<User> root = criteriaQuery.from(User.class); criteriaQuery.where(root.join("roles").in(roles)); TypedQuery<User> query = entityManager.createQuery(criteriaQuery); query.getResultList(); This is the exception: java.lang.IllegalArgumentException: Parameter value [ROLE_2] was not matching type [java.util.Set] at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:360) at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:359) at org.hibernate.ejb.criteria.CriteriaQueryCompiler$1$1.bind(CriteriaQueryCompiler.java:194) at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:247) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:437) ... This all works with OpenJPA 2.0.0

    Hibernate JIRA | 6 years ago | Koen Molkenboer
    java.lang.IllegalArgumentException: Parameter value [ROLE_2] was not matching type [java.util.Set]
  3. 0

    multiply QuerySyntaxException after Update from 2.9.0 to 3.2.1

    GitHub | 3 years ago | bennixview
    java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: * near line 1, column 47 [select case when baa.einheit = ?1 then baa.id * ?2 when baa.einheit = ?3 then baa.id * ?4 else baa.id end from de...............Baa baa]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Filter does not search by numeric fields

    GitHub | 4 years ago | ikostenko
    java.lang.IllegalArgumentException: Parameter value [%49.00%] did not match expected type [java.math.BigDecimal]
  6. 0

    Filter: no validation for fixed format fields

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

    1 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 [ROLE_2] was not matching type [java.util.Set]

      at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding()
    2. Hibernate EJB
      AbstractEntityManagerImpl.createQuery
      1. org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:360)
      2. org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:359)
      3. org.hibernate.ejb.criteria.CriteriaQueryCompiler$1$1.bind(CriteriaQueryCompiler.java:194)
      4. org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:247)
      5. org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:437)
      5 frames