3 Replies Latest reply on Feb 22, 2007 11:10 AM by Alex Grönholm

    HQL and enum constants

    Alex Grönholm Novice

      According to the Hibernate manual, it is possible to use public static final constants directly in HQL queries.
      Why then can I not use enums there as well?
      I tried

      SELECT DISTINCT m FROM Material m, IN(m.suppliers) s WHERE m.unit <> Material.MaterialUnit.SQUARE_METRES AND s.id = :id
      

      and variations like "MaterialUnit.SQUARE_METRES" and the fully qualified name, but they all produce the same error message on deployment:

      13:55:36,982 ERROR [SessionFactoryImpl] Error in named query: Material.nonCuttables
      org.hibernate.hql.ast.QuerySyntaxException: Invalid path: 'null.MaterialUnit.SQUARE_METRES' [SELECT DISTINCT m FROM fi.karico.etikettu.domain.Material m, IN(m.suppliers) s WHERE m.unit <> Material.MaterialUnit.SQUARE_METRES AND s.id = :id]

      The same works fine if I just input the enum as a parameter:
      SELECT DISTINCT m FROM Material m, IN(m.suppliers) s WHERE m.unit <> :m2unit AND s.id = :id
      

      What am I doing wrong?