Jadira is the home for Sousan and Chris Pheby's open source projects. These are reusable open source Java modules that provide first class solutions using the most effective current JEE technologies.

Tag Cloud

Jadira Support > PersistentEnum does not convert constants in HQL queries


If I use an enum constant in a query, Hibernate does not uses the identifierMethod parameter from the PersistentEnum to get the right SQL query.

For instance, using the enum

public enum YesNo {

and the query "SELECT f FROM Entity AS f WHERE f.YesNoField = YesNo.YES" breaks HQL query.

I've managed to get it working by overriding PersistentEnum's "objectToSQLString" method:

public class CustomPersistentEnum extends PersistentEnum {

private Method identifierMethod;

protected void setIdentifierMethod(final Method identifierMethod) {
this.identifierMethod = identifierMethod;

public String objectToSQLString(final Object object) {
if (identifierMethod != null) {
try {
return String.valueOf(identifierMethod.invoke(object));
} catch (InvocationTargetException ignored) {
} catch (IllegalAccessException ignored) {

return super.objectToSQLString(object);

March 4, 2013 | Unregistered CommenterAdriano Machado

Thanks Adriano, this issue has also been reported via the issue tracker at https://jadira.atlassian.net/browse/JDF-36 and will be fixed in the next release.

March 23, 2013 | Registered CommenterChris