问题
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.
回答1:
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);
回答2:
This is a very misleading error, and may root from different causes, for me I was setting a parameter that it was supposedly a number but at runtime it was setting null
, hence it was binary
. On a separate occasion got this error due to bean creation error in spring and was not setting the parameter correctly as well.
回答3:
I encountered this same exception and found the below reason for that -
In my entity, a field was mapped to a custom object (Parent child relationship - @ManyToOne). Later, the relationship annotation was removed by developer but the datatype was not changed.
After removing the @ManyToOne annotation, the @Column annotation should have been used with appropriate data type (Integer).
来源:https://stackoverflow.com/questions/23218102/java-sql-sqlexception-ora-00932-inconsistent-datatypes-expected-number-got-bi