title: Hibernate + nvl()= Oracle 01465
body: <p>Oracle error when attempting to execute a native SQL query that uses a null parameter value. I've boiled it down to this test case:</p>
  
  <pre><code>
  
        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());
           …
  
  </code>
  </pre>
  
  <p>the query uses Oracle's <code>NVL</code> function to handle <code>null</code> parameters.
  However, when I run this code, it fails with an error on the <code>q.getResultList ()</code> call. </p>
  
  <p>The error is as follows:</p>
  
  <blockquote>
  <pre><code>ORA-01465:  invalid hex number
  </code></pre>
  </blockquote>
  
  <p>Now, i'm resolved this problem as </p>
  
  <pre><code>  q.setParameter("svhlick", (entity.getSvhlick() == null ? " " : entity.getSvhlick()));
  </code></pre>
  
  <p>But this'is solution is not good.</p>
  
  <p>Database Oracle 11gR2  win1251 encoding. </p>
  
  <p>Netbeans 7.3.1 project encoding UTF-8.</p>
  
  <p>entity.getSvhlick() - String
  svhlick in Oracle - varchar2(1)</p>
  
  <p>I think the problem may be due to different encoding. </p>
  
  <p>Any Help?</p>