title: How to map a byte[] property with Hibernate?
body: <p>I'm using Hibernate/Java to persist an entity to a database. The entity has a <em>password</em> field which is a <strong>String</strong>. When registring a user in my application, I hash the password using SHA-1 (I acknowledge this is a little weak). This produces a <strong>byte[]</strong> which I then convert to <strong>String</strong> using
     <code>new String(byte[] arr);</code>
  Whenever I want to log a user in, I simply retrieve the hashed password from the database (as <strong>String</strong>) and compare it with the digest of the input password at login using
     <code>hashedPasswordFromDatabase.equals(SHA1_HASH(inputPassword));</code></p>
  
  <p><strong>This worked perfectly</strong> on my development system (Windows 7, JDK 1.6.0_23 / JDK 1.7, MySQL 5.5, Tomcat 6.0.26) but upon deploying it on our server (running JDK 1.6 on Linux), the <em>equals</em> method never evaluates to TRUE even for equal passwords. I quickly setup a new development system (Ubuntu 12.04, MySQL 5.5, JDK 1.7.0_03, Tomcat 7.0.22) and it doesn't work there too. </p>
  
  <p>I'm aware of the possible encoding issues stated in the Java API documentation for the <strong>String</strong> class and also stated in several places here on SO. I've tried a couple of encodings suggested on this forum (e.g Base64, Latin-1) and I ended up with <strong>UnsupportedEncodingException</strong>. I think I'll be better off avoiding the String conversion. So how do I design my database such that the Hibernate-generated entity class comes up with <strong>byte[]</strong> for the <em>password</em> field instead of <strong>String</strong>?</p>