java.sql.SQLException: ORA-00932: 不一致的数据类型: 预期 NUMBER got BINARY

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23218102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 21:24:00  来源:igfitidea点击:

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

javasqloraclenamed-query

提问by techGaurdian

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

我在 Dao 类中有一个返回的方法List<Object[]>,我正在使用命名查询

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> strIdsin stringId into the named query as follows :

我想将List<Integer> strIdsstringId传递到命名查询中,如下所示:

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.

但我得到 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> strIdsinto the query it works fine.

此外,当我sv.R_ID IN (:stringId)从查询中删除时,它工作正常,当我传递Integer (strIds)而不是List<Integer> strIds进入查询时,它工作正常。

I'm using Oracle 10g.

我正在使用 Oracle 10g。

采纳答案by Michael Legart

I think you just need to use

我认为你只需要使用

 IN :stringId

instead of

代替

 IN (:stringId)

For JPA

对于 JPA

namedQuery.setParameter("stringId", strIds);

is correct, but for Hibernate you should use

是正确的,但对于 Hibernate,您应该使用

namedQuery.setParameterList("stringId", strIds);

回答by Ujjwal

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.

在我的实体中,一个字段被映射到一个自定义对象(父子关系 - @ManyToOne)。后来,开发人员删除了关系注释,但数据类型没有改变。

After removing the @ManyToOne annotation, the @Column annotation should have been used with appropriate data type (Integer).

删除@ManyToOne 注释后,@Column 注释应该已与适当的数据类型(整数)一起使用。

回答by mel3kings

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.

这是一个非常具有误导性的错误,并且可能源于不同的原因,对我来说,我正在设置一个参数,它应该是一个数字,但在运行时它正在设置null,因此它是binary. 在单独的情况下,由于 spring 中的 bean 创建错误而出现此错误,并且也没有正确设置参数。