title: JDBC MySQL character encoding: Why is useUnicode required?
body: <p>I am confused about the Character Encoding of Mysql.
  I configure connection.url in Hibernate like this :</p>
  
  <pre><code>&lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/Bag&lt;/property&gt;
  &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
  </code></pre>
  
  <p>the entity class is :</p>
  
  <pre><code>@Entity
  @Table(name = "notification")
  public class Notification {
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = "id")
  private long id;
  
  @Column(name = "username", unique = true,nullable = false, length = 64)
  private String username;
  
  @Column(name = "title", nullable = false, length = 64)
  private String title;
  
  @Column(name = "message", nullable = false, length = 1000)
  private String message;
  
  @Column(name = "uri", nullable = true, length = 256)
  private String uri;
  
  public long getId() {
      return id;
  }
  
  public void setId(long id) {
      this.id = id;
  }
  
  public String getUsername() {
      return username;
  }
  
  public void setUsername(String username) {
      this.username = username;
  }
  
  public String getTitle() {
      return title;
  }
  
  public void setTitle(String title) {
      this.title = title;
  }
  
  public String getMessage() {
      return message;
  }
  
  public void setMessage(String message) {
      this.message = message;
  }
  
  public String getUri() {
      return uri;
  }
  
  public void setUri(String uri) {
      this.uri = uri;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I have create a table in mysql called 'notification':</p>
  
  <pre><code>notification | CREATE TABLE `notification` (
    `id` bigint(20) NOT NULL,
    `message` longtext NOT NULL,
    `title` varchar(64) NOT NULL,
    `uri` longtext,
    `username` varchar(64) NOT NULL,
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
  </code></pre>
  
  <p>when I insert a Chinese String,it can't work well:</p>
  
  <pre><code>mysql&gt; select * from notification;
  +----+---------------------------------+--------------------+------+
  | id | message          | title          | uri          |username |
  +----+---------------------------------+--------------------+--------
  |  1 | ??,????????      | ????           |/post/toPluto | pluto    |
  </code></pre>
  
  <p>I have solved the problem by changing connection.url to :</p>
  
  <pre><code>&lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/Bag?useUnicode=true&amp;amp;characterEncoding=UTF-8&lt;/property&gt;
  </code></pre>
  
  <p>But I don't know the reason,could someone tell me the reason?</p>
  
  <p>this is mysql character_set</p>
  
  <pre><code>Variable_name Value                                                                     
  | character_set_client     | utf8    
  |
  | character_set_connection | utf8          
  |
  | character_set_database   | utf8     
  | character_set_filesystem | binary        
  |
  | character_set_results    | utf8    
  |
  | character_set_server     | latin1    
  |
  | character_set_system     | utf8     
  |
  | character_sets_dir       | /usr/local/mysql-5.7.11-       
  
  osx10.9x86_64/share/charsets/ |
  </code></pre>
  
  <p>this is the hex of Chinese String:</p>
  
  <pre><code>mysql&gt; select hex(message) from notification;
  +----------------------------------------------------------------+
  | hex(message)                                                   |
  +----------------------------------------------------------------+
  | 3F3F2C3F3F3F3F3F3F3F3F
  </code></pre>