IllegalArgumentException when binding arbitrarily typed data to a query where a custom property type is expected in Hibernate
Issue
- A custom type (e.g.
EmployeeState
) is declared for an entity property. - The entity property is annotated with a user type handler implementation (e.g.
EmployeeStateType
) which suppliesnullSafeSet(...)
,nullSafeGet(...)
, etc. - The
nullSafeSet(...)
method is implemented to handle types other than the declared entity property type (e.g.String
as well as the requiredEmployeeState
type). -
When binding a
String
parameter to a named query in place of the custom type (i.e.EmployeeState
) an exception is raised:... java.lang.IllegalArgumentException: Parameter value [Active] did not match expected type [support.hibernate.entity.EmployeeState (n/a)] at org.hibernate.query.spi.QueryParameterBindingValidator.validate(QueryParameterBindingValidator.java:54) at org.hibernate.query.spi.QueryParameterBindingValidator.validate(QueryParameterBindingValidator.java:27) at org.hibernate.query.internal.QueryParameterBindingImpl.validate(QueryParameterBindingImpl.java:90) at org.hibernate.query.internal.QueryParameterBindingImpl.setBindValue(QueryParameterBindingImpl.java:55) at org.hibernate.query.internal.AbstractProducedQuery.setParameter(AbstractProducedQuery.java:497) at org.hibernate.query.internal.AbstractProducedQuery.setParameter(AbstractProducedQuery.java:110) ...
- In Hibernate 3, no exception was raised.
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 7
- Hibernate 5
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.