【问题标题】:SpringJPA - inconsistent datatypes: expected NUMBER got BINARYSpring JPA - 不一致的数据类型:预期 NUMBER 得到 BINARY
【发布时间】:2021-09-08 04:59:38
【问题描述】:

我在我的应用程序中使用 SPRING JPA 并尝试按如下方式运行本机查询:

@Query (value="select max(ts) from abc.test s         \n" + 
                        "where abc.getTest(s.user_id)  = :#{#userId}            \n" + 
                        "and upper(app_name) = 'TAX' and INSTR(s.user_id, '.') > 0        \n" + 
                        "group by user_id, app_name", nativeQuery=true)
Timestamp getLastLogin(BigDecimal userId);

我得到如下异常:

Caused by: Error : 932, Position : 110, Sql = select max(ts) from abc.test s         
where ac.getTest(s.user_id)  = :1             
and upper(app_name) = 'TAX' and INSTR(s.user_id, '.') > 0        
group by user_id, app_name, OriginalSql = select max(ts) from abc.test s         
where abc.getTest(s.user_id)  = ?            
and upper(app_name) = 'TAX' and INSTR(s.user_id, '.') > 0        
group by user_id, app_name, Error Msg = ORA-00932: inconsistent datatypes: expected NUMBER got BINARY

    at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:514)
    ... 109 more
<org.hibernate.engine.jdbc.spi.SqlExceptionHelper> <SqlExceptionHelper> <logExceptions> <SQL Error: 932, SQLState: 42000> 
<org.hibernate.engine.jdbc.spi.SqlExceptionHelper> <SqlExceptionHelper> <logExceptions> <ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
> 

我尝试使用 to_char 将 max(ts) 转换为字符串,并将对应的 getter/setter 更改为 String 仍然遇到同样的问题。

更新: 我用这个小改动修复了它

String getLastLogin(@Param("userId") BigDecimal userId); 没有为参数添加@Param。

【问题讨论】:

  • 函数abc.getTest返回什么oracle类型?
  • @SternK 谢谢。我已经编辑了我的帖子并修复了该问题

标签: sql spring hibernate jpa spring-data-jpa


【解决方案1】:

该查询返回空值,这就是为什么空值不能分配给数字的原因。我们不能在 java 中将 null 分配给 int(primitive)。

【讨论】:

  • 谢谢。我已经编辑了我的帖子并修复了问题
猜你喜欢
  • 1970-01-01
  • 2017-04-21
  • 2014-06-06
  • 2019-05-04
  • 2017-11-26
  • 1970-01-01
  • 2019-08-25
  • 1970-01-01
  • 2017-12-28
相关资源
最近更新 更多