File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Android Security Essentials Live Lessons this week in the Android 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

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

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

Joined: May 26, 2003
Posts: 30138

@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
wood burning stoves
subject: @NamedQuery : does it have to be declared on an @Entity ?
Similar Threads
populating @OneToOne from query
JPA composite key mapping
Coming from ibatis, so new, but stumped on how to set this up (multiple collections )
jsf navigation and database connection
building a search feature in my application, what is the best approach