title: JPA EntityManager and character encoding
body: <p>For the first time, I'm creating a simple website with JSP, Servlets, a Tomcat server, MySQL and Netbeans (if that helps).</p>
  
  <p>Thanks to JPA <strong>EntityManager</strong>, I can insert data into my database like this :</p>
  
  <pre><code>    EntityManager entityManager = Persistence.createEntityManagerFactory("test").createEntityManager();
      entityManager.getTransaction().begin();
      entityManager.persist(usr);
      entityManager.getTransaction().commit();
  </code></pre>
  
  <p>Where usr is an Entity Class <em>User</em> generated thanks to Netbeans. 
  Everything works perfectly except the fact that it doesn't support characters such as accents.</p>
  
  <p>Assuming I want to insert the word "cliché" :</p>
  
  <ul>
  <li>If I try to print the value from my <em>User</em> class, everything is fine.</li>
  <li>When the value is sent, if I try to SELECT the value from my base, I've got strange characters instead of the "é"</li>
  </ul>
  
  <p>Database fields are <strong>utf8_unicode_ci</strong>. If I try to make a simple INSERT from MySQL prompt such as</p>
  
  <pre><code>INSERT INTO table (name) VALUES("ééé");
  </code></pre>
  
  <p>it's working perfectly.</p>
  
  <p>As I read on some websites, I modified my <strong>persistence.xml</strong> with the following line :</p>
  
  <pre><code>&lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;amp;characterEncoding=UTF-8&amp;amp;characterSetResults=UTF-8&amp;amp;zeroDateTimeBehavior=convertToNull"/&gt;
  </code></pre>
  
  <p>but the result is the same.</p>
  
  <p>EDIT : Here are the properties of my <em>User Class</em></p>
  
  <pre><code>@Entity
  @Table(name = "users")
  @XmlRootElement
  @NamedQueries({
      @NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u"),
      @NamedQuery(name = "Users.findByIdUsers", query = "SELECT u FROM Users u WHERE u.idUsers = :idUsers"),
      @NamedQuery(name = "Users.findByUsername", query = "SELECT u FROM Users u WHERE u.username = :username"),
      @NamedQuery(name = "Users.findByPasswd", query = "SELECT u FROM Users u WHERE u.passwd = :passwd"),
      @NamedQuery(name = "Users.findByFirstName", query = "SELECT u FROM Users u WHERE u.firstName = :firstName"),
      @NamedQuery(name = "Users.findByLastName", query = "SELECT u FROM Users u WHERE u.lastName = :lastName"),
      @NamedQuery(name = "Users.findByEmail", query = "SELECT u FROM Users u WHERE u.email = :email"),
      @NamedQuery(name = "Users.findByEmailAndPwd", query = "SELECT u FROM Users u WHERE u.email = :email AND u.passwd = :passwd")})
  public class Users implements Serializable {
      @Basic(optional = false)
      @Column(name = "address")
      private String address;
      @Basic(optional = false)
      @Column(name = "city")
      private String city;
      @Basic(optional = false)
      @Column(name = "postal")
      private String postal;
      @Basic(optional = false)
      @Column(name = "phone")
      private String phone;
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "idUsers")
      private Integer idUsers;
      @Basic(optional = false)
      @Column(name = "username")
      private String username;
      @Basic(optional = false)
      @Column(name = "passwd")
      private String passwd;
      @Basic(optional = false)
      @Column(name = "firstName")
      private String firstName;
      @Basic(optional = false)
      @Column(name = "lastName")
      private String lastName;
      @Basic(optional = false)
      @Column(name = "email")
      private String email;
  </code></pre>
  
  <p>As I read on the web, I also tried to modify my <strong>catalina.bat</strong> by adding the following lines but it didn't change anything.</p>
  
  <blockquote>
    <p>set JAVA_OPTS=%JAVA_OPTS% -Djavax.servlet.request.encoding=UTF-8
    -Dfile.encoding=UTF-8</p>
  </blockquote>
  
  <p>Any help is much appreciated.</p>