title: Getting Hibernate and SQL Server to play nice with VARCHAR and NVARCHAR
body: <hr>
  
  <p>I'm currently in the process of enabling UTF-8 characters in some tables of a large database. These tables are already of MS-SQL type NVARCHAR.  Additionally, I have several fields using VARCHAR as well.  </p>
  
  <p>There is a well known issue with Hibernate's interactions with the JDBC driver (see e.g., <a href="https://stackoverflow.com/questions/1306774/mapping-to-varchar-and-nvarchar-in-hibernate">Mapping to varchar and nvarchar in hibernate</a>) . In short, Hibernate/JDBC generates SQL that passes all strings as Unicode, regardless of the underlying SQL type. When a non-unicode (varchar) field in the database is compared to a Unicode input string, the indicies for that column do not match the encoding so a full table scan is performed. In the JDBC driver (both JTDS and MS versions) there is a parameter to pass Unicode strings as ASCII, but this is an all or nothing proposition that disallows international characters from being input into the the database. </p>
  
  <p>Most posts I've seen on this issue have come up with one of two solutions - 1) change everything in the database to NVARCHAR or 2) set the sendStringParametersAsUnicode=false, 
  My question then is this - is there any known solution for having VARCHAR and NVARCHAR play nicely together? It is a <strong>huge</strong> issue for my environment to change everything to NVARCHAR because of downstream dependencies and other external issues.</p>