views:

189

answers:

2

I wrote a named query in the entity class Voter

NamedQuery(name = "Voter.findvoter", query = "SELECT count(*) FROM Voter v WHERE v.voterID = :voterID" and where v.password= : password),

I want to call this named query and I also need to set voterID and password.

Can you help me. Thank you

+3  A: 

I assume you've missed the @ symbol on your NamedQuery annotation?

In the code, you'd call it like this:

List results = em.createNamedQuery("Voter.findvoter")
    .setParameter("voterID", "blah")
    .setParameter("password","blahblahblah")
    .getResultList();
Dick Chesterwood
+1  A: 

The common steps are (named query or otherwise)

  1. Create a query - em has five create methods.
  2. Set the query up with parameters if needed - the query interface has these methods.
  3. Execute the query - the query interface has 3 execution related methods.

with the above three steps you can run any JPA query.

OpenSource