wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes @NamedQuery : does it have to be declared on an @Entity ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "@NamedQuery : does it have to be declared on an @Entity ?" Watch "@NamedQuery : does it have to be declared on an @Entity ?" New topic
Author

@NamedQuery : does it have to be declared on an @Entity ?

Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 311
I'm new to ejb, and trying to use @NamedQuery.
When you declare @NamedQuery (using annotations, not XML), do you have to declare it on an @Entity class ?

I mean:

I couldn't get the second example to work.
I even tried declaring the NotEntityClass in persistence.xml, but it didn't work - maybe I did it wrong ?
<class>somePackage.NotAnEntity<class>

Is there some way to make it work ?
Thank you.
[ October 03, 2007: Message edited by: Sol Mayer-Orn ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

Sol,
@NamedQuery does need to be declared on an @Entity class. As you noted, the alternative is to put it in XML.

As I recall, it goes in the orm.xml file. For example:


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @NamedQuery : does it have to be declared on an @Entity ?