1

How do I exactly write the following query using entityManager.

Select * from TABLE_NAME where column_name in ('A', 'B');

I tried with the setParametrList() method. However, it says that this method is not available for type Query.

Query query = entityManager.createQuery(
                "Select t from  TableEntity t WHERE t.name =:bd AND t.staus in (:statuses)", TableEntity .class)
                .setParameter("bd", bd)
                .setParameterList("statuses", statuses);

Error: The method setParameterList(String, List<String>) is undefined for the type TypedQuery<TableEntity >

The same method seems to work fine while using session.createQuery. Any suggestions on this.

Saurabh Tiwari
  • 4,632
  • 9
  • 42
  • 82
  • Related: [Doing an β€œIN” query with Hibernate](https://stackoverflow.com/questions/3126366/doing-an-in-query-with-hibernate) – Tim Biegeleisen Apr 15 '19 at 09:13

1 Answers1

1

Just use setParameter("statuses", statuses) with the list. The method checks if the parameter is a collection and expands it.

coladict
  • 4,799
  • 1
  • 16
  • 27
  • Also by JPA standard, the syntax is `t.staus in :statuses`, but I'm fairly certain Hibernate allows `t.staus in (:statuses)` – coladict Apr 15 '19 at 09:14