title: Hibernate, Spring and MySQL : unable to set the charset to UTF-8
body: <p>I have an issue with Hibernate and Spring : I am unable to use the UTF-8 charset everywhere, and I have some issues with accented letters (like <em>éèà</em>...). Here is a part of my database creation :</p>
  
  <pre><code>-- Dropping and creating database again
  DROP DATABASE `miniprojetjee`;
  CREATE DATABASE IF NOT EXISTS `miniprojetjee` default character set = "UTF8" default collate = "utf8_general_ci";
  
  -- My user
  GRANT ALL ON `miniprojetjee`.* to 'miniprojetjee'@'localhost' identified by 'miniprojetjee';
  
  CREATE TABLE Utilisateur (
      username VARCHAR(45) NOT NULL ,
      password VARCHAR(45) NOT NULL ,
      enabled TINYINT NOT NULL DEFAULT 1 ,
      telephone VARCHAR(20),
      mail VARCHAR(255) NOT NULL,
      description MEDIUMBLOB,
      date_inscription TIMESTAMP DEFAULT NOW(),
      PRIMARY KEY (username)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  
  -- .../...
  </code></pre>
  
  <p>I think this implies that my database is in full UTF-8. So after this, I configured spring and hibernate through my <code>web.xml</code>...</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
           version="3.1"&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/dispatcher-servlet.xml, /WEB-INF/spring-security.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  
  &lt;!-- .../... --&gt;
  </code></pre>
  
  <p>And my <code>dispatcher.xml</code> :</p>
  
  <pre><code>&lt;!-- .../... --&gt;
  &lt;bean id="dataSourceMySql" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
      &lt;property name="url" value="jdbc:mysql://localhost:3306/miniprojetjee?useUnicode=true&amp;amp;connectionCollation=utf8_general_ci&amp;amp;characterSetResults=utf8"/&gt;
      &lt;property name="username" value="miniprojetjee"/&gt;
      &lt;property name="password" value="miniprojetjee"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSourceMySql"/&gt;
      &lt;property name="packagesToScan" value="dao"/&gt;
  
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="show_sql"&gt;${hibernate.show_sql}&lt;/prop&gt;
              &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt;
              &lt;prop key="hibernate.connection.useUnicode"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.connection.characterEncoding"&gt;UTF-8&lt;/prop&gt;
              &lt;prop key="hibernate.connection.charSet"&gt;UTF-8&lt;/prop&gt;
              &lt;!-- Tryied a lot of things...
              &lt;prop key="connection.useUnicode"&gt;true&lt;/prop&gt;
              &lt;prop key="connection.characterEncoding"&gt;UTF-8&lt;/prop&gt;
              &lt;prop key="connection.charSet"&gt;UTF-8&lt;/prop&gt;
              &lt;prop key="useUnicode"&gt;true&lt;/prop&gt;
              &lt;prop key="characterEncoding"&gt;UTF-8&lt;/prop&gt;
              &lt;prop key="charSet"&gt;UTF-8&lt;/prop&gt;
              --&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;!-- .../... --&gt;
  </code></pre>
  
  <p>Is there any way to solve this ? I am unable to find anything that work right now.</p>