Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Only one named query allowed???

 
Greg Reinl
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Sheriff
Posts: 35977
422
Eclipse IDE Java VI Editor
 
Shailesh Kini
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greg Reinl
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does. Thanks.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!