title: Mapping to varchar and nvarchar in hibernate
body: <p>If there are 2 columns in database, eg.</p>
  
  <pre><code>code varchar(3)
  name nvarchar(50)
  </code></pre>
  
  <p>How to tell hibernate to pass varchar for searching by code?</p>
  
  <p>In the hibernate mappings string is mapped to nvarchar and it produces queries like:</p>
  
  <pre><code>Select code, name From table where code=N'AAA'  (instead of code='AAA')
  </code></pre>
  
  <p>This is very bad as it causes index scan instead of index seek operation (scanning all index nodes instead of directly going to requested one)</p>
  
  <p>As code is used in millions of rows as well as in several indexes and foreign keys, changing it from varchar to nvarchar will cause performance degradation (more IO operations as nvarchar uses twice more space than varchar).</p>
  
  <p>Is there any way to tell hibernate to do mapping according to database type, not to Java type?</p>
  
  <p>Thanks</p>