title: Same Query behaving differently when executed from JPA or directly in the DB
body: <p>I have the following JPQL Query </p>
  
  <pre><code>    SELECT g                                        
      FROM MyEntity g
      WHERE g.fieldA      = :parA
      AND (g.pk.fieldB = :parB
         OR ' ' = :parB  )
  </code></pre>
  
  <p>after some trial I understood the problem is</p>
  
  <pre><code>OR ' ' = :parB
  </code></pre>
  
  <p>Suppose fieldB is defined as CHAR 3 in the database. </p>
  
  <p>If I use</p>
  
  <pre><code> parB = " "
  </code></pre>
  
  <p>the query works as expected, but if </p>
  
  <pre><code>parB = "abc" 
  </code></pre>
  
  <p>I get an SQL Error (<em>DB2 error CODE -302: THE VALUE OF INPUT VARIABLE OR PARAMETER NUMBER position-number IS INVALID OR TOO LARGE FOR THE TARGET COLUMN OR THE TARGET VALUE</em>)</p>
  
  <p>I can imagine the problem is in the length of ' ' compared to "abc", what I not really understand is why.. I copied the generated sql and if I execute it using for example Squirrel SQL it works nice:</p>
  
  <pre><code>OR ' ' = 'abc' 
  </code></pre>
  
  <p>doesn't make any problem.</p>
  
  <p>Can you please explain me what happens with the string when the query is prepared? Is it possible to adjust this query?</p>
  
  <p>Thanks in advance!</p>