3 Replies Latest reply on Feb 2, 2011 8:20 AM by Wolf-Dieter Fink

    Using enum "fields" in hql

    Jaber C. Mourad Novice



      I have this enum :


      public enum ValidationState {
             * Waiting for validation
             * Validated but cancellable (not taken yet !)
             * Canceled period
             * Validated and uncancellable (date is over)
            private final boolean cancelable;
            private ValidationState(){
            private ValidationState(boolean cancelable){
                  this.cancelable = cancelable;
            public boolean isCancelable(){
                  return this.cancelable;


      I'm using it in an entity :


            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.