buttowski
buttowski

Reputation: 4917

select filter records from table using jpa entity manager

i want to find entiries in table with filter conditions as below using jpa enity manager

select * from My_Table where (status='A' or status='Z' or status='NA')

please suggest a way to do this..

Upvotes: 1

Views: 1329

Answers (1)

Kevin Bowersox
Kevin Bowersox

Reputation: 94499

Assuming the following:

  1. em = EntityManager
  2. MyTable = My_Table entity
  3. MyTable has a status field.

Java

public List findByStatus() {
    return em.createQuery(
        "SELECT mt FROM MyTable mt WHERE mt.status in ('A', 'Z', 'NA')")
        .getResultList();
}

Upvotes: 3

Related Questions