简体   繁体   中英

EJB3 Query + in clause

I need to use an IN clause like the following SQL

SELECT * FROM tableA WHERE colA in (1, 2,3)

How can i do this in EJBQL?

i've tryed the following, which obviously failed:

SELECT tab FROM tableA tab WHERE tab.colA in (:colValues)

then in java i did

query.setParameter("colValues","1,2,3")

that gives me the following exception

org.apache.openjpa.lib.jdbc.ReportingSQLException: ORA-01722: invalid number

The problem is when you use :parameter_name in an sql fragment and then call query. setParamter("parameter_name", values) query. setParamter("parameter_name", values) it is expected that values should be some sort of collection . Try this.

List<Integer> values = new ArrayList<Integer>();
values.add(1);
values.add(2);
values.add(3);

query.setParameter("colValues", values);

It's been a long while since I've done EJBQL, but this should work:

  SELECT OBJECT(t)
       FROM Tab AS t
       WHERE t.colA IN (:colValues)

Also, you may need to set colValues as an array of numbers rather than a string

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM