[jboss-user] [EJB3] - Weired JPA named query @NamedQuery behaviour

Christian Groove do-not-reply at jboss.com
Sun Jan 23 17:54:03 EST 2011


Christian Groove [http://community.jboss.org/people/TheGroove] created the discussion

"Weired JPA named query @NamedQuery behaviour"

To view the discussion, visit: http://community.jboss.org/message/582625#582625

--------------------------------------------------------------
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 ???
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/582625#582625]

Start a new discussion in EJB3 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110123/0dfbbf60/attachment.html 


More information about the jboss-user mailing list