It appeared that the final String parameter set in the SQL query was not the one I expected. Logging the SQL parameters (org.hibernate.type=TRACE
) shows that the parameter looks like some hash (2c6d8085fef280...), not a regular String. While debugging the SQLQuery, i saw that the namedparameter's type was of type SerializableType
instead of StringType
. Hence Hibernate calls NullableType.nullSafeSet()
in his Loader.bindNamedParameters()
method, that calls Serializable.set()
, which sets the Enum value as bytes.
So the problem seems to come from TypeFactory.heuristicType()
that doesn't find any suitable type for my Enum, except SerialisableType.
I didn't find any corresponding JIRA on hibernate bugtracker or anything else on Google, except that https://forum.hibernate.org/viewtopic.php?f=9&t=984527 so I don't really know if it's worth reporting the bug (maybe that branch is not even maintained anymore?)
don't set enum parameters in SQLQuery!
// don't do
sqlQuery.setParameter("myStatus", MyStatusEnum.OK); // NOP!
// instead, do
sqlQuery.setParameter("myStatus", MyStatusEnum.OK.name()); // YEP!
// or even, to be sure
sqlQuery.setString("myStatus", MyStatusEnum.OK.name()); // YEP!