The moose likes Object Relational Mapping and the fly likes Only one named query allowed??? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Only one named query allowed???" Watch "Only one named query allowed???" New topic
Author

Only one named query allowed???

Greg Reinl
Ranch Hand

Joined: Feb 11, 2003
Posts: 45
I am using annotion to create named queries for an EJB. When I add one annotation it works fine but when I addthe second I get this compile error:

Error(10,2): duplicate annotation javax.persistence.NamedQuery

The annotations at the class level look like this:

@Entity
@NamedQuery(name = "Response.findAll", query = "select o from Response o")
@NamedQuery(name = "Response.searchForText",
query = "select o from Response o where o.question Like :text")

Is ther no way to associate multiple named queries with one EJB?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 23632

Moving to our JPA forum.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Certs: SCEA Part 1, Part 2 & 3 & Core Spring 3, OCAJP
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
Hi Greg,

There is a way to add multiple Named Queries to your entity.

@NamedQueries( { @NamedQuery(name = "Response.findAll query = "select o from Response o"), @NamedQuery(name = "Response.searchForText" query = "SELECT o from Response o where o.question like :text")})

Hope this helps


Shailesh Kini.
Greg Reinl
Ranch Hand

Joined: Feb 11, 2003
Posts: 45
It does. Thanks.
 
IntelliJ Java IDE
 
subject: Only one named query allowed???
 
Threads others viewed
Dynamically setting sort direction
named queries can be defined only on an entity - problem
@ManyToMany delete problem
Unable to use @NamedQuery in a session bean?
NamedQuery: Retrieve more than one field?!?
IntelliJ Java IDE