hibernate + nvl()= 甲骨文 01465

标签 hibernate encoding entitymanager nvl

尝试执行使用空参数值的 native SQL 查询时出现 Oracle 错误。我把它归结为这个测试用例:



      String SQL_SELECT = 
        "select * from act t1 where t1.G074=:G074 AND t1.G542=:G542 AND 
        nvl(t1.svhlick,' ')=nvl(:svhlick,' ') 
        and  t1.svhlic=:svhlic 
        and t1.sf$version =
          (select max(sf$version) from act t2 where t2.G074=t1.G074 and t2.G542=t1.G542 AND nvl
        (t2.svhlick,' ')=nvl(t1.svhlick,' ') and t2.svhlic=t1.svhlic)";
        Query q = em.createNativeQuery(SQL_SELECT, Act.class);
        ….
           q.setParameter("svhlick", entity.getSvhlick());
         …


the query uses Oracle's NVL function to handle null parameters. However, when I run this code, it fails with an error on the q.getResultList () call.

The error is as follows:

ORA-01465:  invalid hex number

Now, i'm resolved this problem as

  q.setParameter("svhlick", (entity.getSvhlick() == null ? " " : entity.getSvhlick()));

但是这个解决方案并不好。

数据库 Oracle 11gR2 win1251 编码。

Netbeans 7.3.1 项目编码 UTF-8。

entity.getSvhlick() - 字符串 Oracle 中的 svhlick - varchar2(1)

我认为问题可能是由于不同的编码。

有什么帮助吗?

最佳答案

我遇到了同样的问题并通过指定类型解决了它:

q.setParameter("svhlick", entity.getSvhlick(), StandardBasicTypes.STRING);

参见 https://forum.hibernate.org/viewtopic.php?f=1&t=984725

关于 hibernate + nvl()= 甲骨文 01465,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18915598/

相关文章:

java - Hibernate:使用集合条件(HashSet)

cocoa - NSUTF8StringEncoding 导致文件在 TextEdit/Pages 中渲染不正确,但在 BBEdit/vi 中则不会

c++ - 为什么在 winapi 中转换 UTF16 -> UTF8 -> UTF16 后文件名有不同的字节?

java - Singleton 中具有上下文类型 TRANSACTION 的 EntityManager 是否会加入外部 bean 管理的事务?

java - 从 grails 的排序集中删除所有项目

java - JPA 在列表/集合上获取连接过滤器

java - 奇怪的 hibernate 缓存行为

java - URLConnection 字符编码

hibernate - 努力了解EntityManager的正确使用

java - 使用 envers 进行 Junit 测试