views:

35

answers:

2

I have a mysql database with unicode text strings in it. My JSF application (running on tomcat 6) can read these unicode strings out and display them correctly in the browser. All the html charsets are set to UTF-8.

When I save my object, even having made no changes, Hibernate persists it back to the database. If I look directly in the database now, I see that characters with accents have become junk.

My database connection string is:

        <property name="hibernate.connection.url"
                  value="jdbc:mysql://database.address.com/dbname?autoReconnect=true&#38;zeroDateTimeBehavior=convertToNull&#38;useUnicode=true&#38;characterEncoding=utf8"/>

Changing that characterEncoding to UTF-8 instead of utf8 makes no difference.

Actually it was working days ago for sure, but now it isn't and I'm out of ideas for what to check. Do you have any suggestions? I can provide any further info deemed relevant.

+1  A: 

Does it only happen on certain tables? Perhaps the DEFAULT CHARSET of those tables is different than the others. (http://dev.mysql.com/doc/refman/5.1/en/charset-table.html)

Dante617
+1  A: 

Some options to resolve that come to my mind:

  • if using facelets, specify <?xml version="1.0" encoding="UTF-8"?> at the top of the page
  • if using JSP, specify <%@ page pageEncoding="utf-8" %>
  • if that does not work, make a filter that is mapped to the faces servlet, and does request.setCharacterEncoding("utf-8")
Bozho