javasqloracle-databasenamed-query

java.sql.SQLException: ORA-00932: inconsistent datatypes: expected NUMBER got BINARY


I have a method in Dao Class that returns List<Object[]> back and I am using named Query

public List<Object[]> getListByCustomer(Session session, int customerId, List<Integer> strIds) {
  Query namedQuery = session.createSQLQuery(QueryConstants.EXPORT);
  namedQuery.setParameter("customer", customerId);
  namedQuery.setParameter("stringId", strIds);
  List<Object[]> objects = namedQuery.list();
  return objects;
}

I want to pass List<Integer> strIds in stringId into the named query as follows :

public class QueryConstants {
  public static final String EXPORT = 
    "SELECT sv.NAME, sv.TYPE, sv.CLIENT_ADDRESS, sv.NAME_REDUNDANT, sv.DEPARTURE_DATE, s1.CODE,sv.STATE, sv.CODE "
    + "FROM VIEW sv, PROCESS p1, SET s1 " 
    + "WHERE sv.R_ID = p1.R_ID and p1.ISSUER_ID = s1.USER_ID and sv.CUSTOMER_ID = :customer and sv.R_ID IN (:stringId)";
}

But I get ORA-00932: inconsistent datatypes: expected NUMBER got BINARY.

Also when I remove sv.R_ID IN (:stringId) from the query it works fine and when I pass Integer(strIds) instead of List<Integer> strIds into the query it works fine.

I'm using Oracle 10g.


Solution

  • I think you just need to use

     IN :stringId
    

    instead of

     IN (:stringId)
    

    For JPA

    namedQuery.setParameter("stringId", strIds);
    

    is correct, but for Hibernate you should use

    namedQuery.setParameterList("stringId", strIds);