I'm having difficulty with UTF-8 characters. This is a simple JSF project. I am using JSF 2.2 and Glassfish 4.0
I have a method by which I go:
em.persist(user);
When i debug
user.getName()
at this point, I see utf-8 characters in my IDE. I also save the string in the bean session, and I also see them in the browser.
Only when they are saved in the database, they are saved as: ?????
I can also edit the database myself and save utf-8 characters. I mean, my SQL configuration is good for UTF-8.
The problem is somewhere in the JPA.
This is what I tried: (all together :)
persistence.xml
<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"> <persistence-unit name="Persistence" transaction-type="JTA"> <jta-data-source>fus</jta-data-source> <class>com.tugay.fup.core.model.User</class> <properties> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/fus?useUnicode=yes&characterEncoding=UTF-8"/> </properties> </persistence-unit> </persistence>
This is glassfish-web.xml:
<glassfish-web-app> <parameter-encoding default-charset="UTF-8"/> </glassfish-web-app>
And I use a container managed EntityManager (transaction type = JTA)
So, in the JDBC connection pools in Glassfish, I have:
jdbc:mysql://localhost:3306/fus?useUnicode=true&connectionCollation=utf8_general_ci&characterSetResults=utf8
for: property: URL ...
However, none of this helps.
Symbols are saved correctly.
java mysql hibernate jpa glassfish
Koray tugay
source share