6 Replies Latest reply on Jan 24, 2011 3:20 PM by Christian Groove

    Weired JPA named query @NamedQuery behaviour

    Christian Groove Newbie

      Salut

       

      i recogniozed a strange behaviour, declaring anmed

      queries with a annotation. Here is some code:

       

       

       

      @NamedQueries(

          {

              @NamedQuery(

                  name=Dbean1.GET_COMPOSITION,

                  query=Dbean1.JPQL_COMPOSITION)

          }

      )

       

       

       

      where:

       

      @Entity

      public class Dbean1. implements Serializable

      {

         /* some code */

       

       

         final public static String GET_COMPOSITION = ".... composition " ;

         final public static String GET_COMPOSITION = "SELECT dbean FROM ..... " ;

       

       

      this looks fine. But imagine iff you a to implement a recurring part of the

      where expression and start thinking of a java code, that could help you to

      create that JPA-QL string.

      So when you write:

       

      @Entity

      public class Dbean1. implements Serializable

      {

         /* some code */

       

       

         final public static String GET_COMPOSITION      = ".... composition " ;


         final public static String GENERATED_WHERE_EXPR = generateWehreCompo() ;


         final public static String GET_COMPOSITION      =

                                "SELECT dbean FROM ..... +

                                WHERE" + GENERATED_WHERE_EXPR  ... ;

       

       

      JBoss5.1 will tell you "The value for annotation attribute NamedQuery.query must be a

      constant expression" So is final private static not constant enough ???