title: Incorrect encoding when initializing database with DataSourceInitializer in Spring Framework
body: <p>I am using Spring Framework 4 and Hibernate 4 together with MySQL database. For initializing database with data I use initialization script configured in hibernate.xml file.</p>
  
  <p>Initialization of database goes alright, but in database appears <code>?</code> instead of characters with diacritics. For example instead of <code>Česko</code> I see <code>?esko</code>.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>database.sql</strong></p>
  
  <pre><code>INSERT INTO COUNTRY (ID, NAME) VALUES (1, 'Slovensko'), (2, 'Česko'), (3, 'Poľsko'), (4, 'Maďarsko');
  </code></pre>
  
  <p><strong>COUNTRY table created by Hibernate</strong></p>
  
  <pre><code>CREATE TABLE `country` (
    `ID` bigint(20) NOT NULL AUTO_INCREMENT,
    `NAME` varchar(100) NOT NULL,
    PRIMARY KEY (`ID`),
    UNIQUE KEY `UK_l7qlysdc1xbo69vsmueersr2k` (`NAME`)
  ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8
  </code></pre>
  
  <p><strong>database.properties</strong></p>
  
  <pre><code>jdbc.driver=com.mysql.jdbc.Driver
  jdbc.url=jdbc:mysql://localhost:3306/BPM?UseUnicode=true;characterEncoding=utf8
  jdbc.username=root
  jdbc.password=root
  </code></pre>
  
  <p><strong>hibernate.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:jdbc="http://www.springframework.org/schema/jdbc"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
            http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"&gt;
  
      &lt;!-- Database properties file --&gt;
      &lt;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
          &lt;property name="locations"&gt;
              &lt;list&gt;
                  &lt;value&gt;classpath:database.properties&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- Configure JDBC Connection --&gt;
      &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="${jdbc.driver}" /&gt;
          &lt;property name="url" value="${jdbc.url}" /&gt;
          &lt;property name="username" value="${jdbc.username}" /&gt;
          &lt;property name="password" value="${jdbc.password}" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- Configure Hibernate 4 Session Facotry --&gt;
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
          &lt;property name="packagesToScan" value="bpm" /&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQL5InnoDBDialect&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;create-drop&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- Initialize database --&gt;
      &lt;jdbc:initialize-database data-source="dataSource"&gt;
          &lt;jdbc:script encoding="utf-8" location="classpath:/data/database.sql" /&gt;
      &lt;/jdbc:initialize-database&gt;
  
      &lt;!-- Transaction Manager --&gt;
      &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>spring.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"&gt;
  
      &lt;context:annotation-config /&gt;
  
      &lt;context:component-scan base-package="bpm"/&gt;
  
      &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  &lt;/beans&gt;
  </code></pre>