title: Hibernate - How to bind parameter as nvarchar
body: <p>I got an oracle database, with a NVARCHAR2(2000 CHAR) field, the hbm file I have generated by hibernate reverse engineering is as below</p>
  
  <pre><code>&lt;property name="remarks" type="string"&gt;
      &lt;column length="4000" name="REMARKS" /&gt;
  &lt;/property&gt;
  </code></pre>
  
  <p>While update this file in database, I found it bind to varchar instead of nvarchar</p>
  
  <pre><code>org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [5] as [VARCHAR]
  </code></pre>
  
  <p>If I enter 2000 Chinese characters, it will exceed its field length.
  <br>How can I make it bind to nvarchar instead?</p>
  
  <p><br>
  <strong>Update</strong>
  <br>
  It is due to Oracle Database I am using. 
  <br>
  <a href="http://docs.oracle.com/cd/B19306_01/java.102/b14355/global.htm#CHDHHJDB" rel="nofollow">Reference - </a>
  "By default, oracle.jdbc.OraclePreparedStatement treats all columns as CHAR."</p>
  
  <p><br>
  <strong>Solution</strong></p>
  
  <p>Turn out I add defaultNChar to JNDI connection property</p>
  
  <pre><code> &lt;connection-property name="defaultNChar"&gt;
       true
   &lt;/connection-property&gt;
  </code></pre>