Using enum "fields" in hql
newbeewan Feb 1, 2011 8:55 AMHi,
I have this enum :
public enum ValidationState { /** * Waiting for validation */ PENDING(true), /** * Validated but cancellable (not taken yet !) */ VALIDATED(true), /** * Canceled period */ CANCELED, /** * Validated and uncancellable (date is over) */ VALIDATE_CLOSED; private final boolean cancelable; private ValidationState(){ this(false); } private ValidationState(boolean cancelable){ this.cancelable = cancelable; } public boolean isCancelable(){ return this.cancelable; } }
I'm using it in an entity :
@Column(name="VALIDATION_STATE") @Enumerated(EnumType.STRING) private ValidationState state;
I want to select some entities via HQL using the value of the cancelable property
I have created that request
FROM ThePeriod period WHERE period.uid = :uid AND period.state.cancelable = true
I've got a QueryException :
org.hibernate.QueryException: could not resolve property: cancelable of: business.data.ThePeriod [FROM ThePeriod period WHERE period.uid = :uid AND period.state.cancelable = true ] at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:81) at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:75) at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1449) at org.hibernate.hql.ast.tree.FromElementType.getPropertyType(FromElementType.java:315) at org.hibernate.hql.ast.tree.FromElement.getPropertyType(FromElement.java:487) at org.hibernate.hql.ast.tree.DotNode.getDataType(DotNode.java:611) at org.hibernate.hql.ast.tree.DotNode.prepareLhs(DotNode.java:263) at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:210)
Is it possible to use the value of an enum's property into an HQL query ?
I'm using hibernate 3.6.0 as entity manager.
Regards