0

I am creating a named JPA query . It needs to fetch all records that meet a manager name and status . This is how i have created .

@NamedQuery(name = "Claims.viewMgrClaims", query = "SELECT c FROM Claims c WHERE c.mgrname = :mgrname AND " 
+ "c.status like :stat")

i created it following the example given here Named Query with like in where clause

I am however unsure how my call should look like . For example i am unsure how to use setParameter with two fields . I used this for a different query and it works fine .

List<Claims> l = em.createNamedQuery("Claims.findByMgrname").setParameter("mgrname", MgrName).getResultList();

But what should i use for my new NamedQuery ? I cant get it right .

Community
  • 1
  • 1
rockstar
  • 3,512
  • 6
  • 40
  • 63

2 Answers2

1

You can call like this:

 List<Claims> l = (List<Claims>)em.createNamedQuery("Claims.findByMgrname")
   .setParameter("mgrname", MgrName)
   .setParameter("stat", statVar)
   .getResultList();
user1697575
  • 2,830
  • 1
  • 24
  • 37
0

I got it after a little more Googling

For people who come here looking here is a good link Named JPA Query With Two Parameters

rockstar
  • 3,512
  • 6
  • 40
  • 63