Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate/JPA import.sql utf8 characters corrupted
    text
    copied!<p>I'm using import.sql to write my development data to DB. I'm using MySQL Server 5.5 and my persistence.xml is here:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt; &lt;persistence-unit name="MobilHM" transaction-type="RESOURCE_LOCAL"&gt; &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt; &lt;class&gt;tr.com.stigma.db.entity.Doctor&lt;/class&gt; &lt;class&gt;tr.com.stigma.db.entity.Patient&lt;/class&gt; &lt;class&gt;tr.com.stigma.db.entity.Record&lt;/class&gt; &lt;class&gt;tr.com.stigma.db.entity.User&lt;/class&gt; &lt;properties&gt; &lt;property name="hibernate.hbm2ddl.auto" value="create" /&gt; &lt;property name="hibernate.show_sql" value="true" /&gt; &lt;property name="hibernate.format_sql" value="true" /&gt; &lt;!-- Auto detect annotation model classes --&gt; &lt;property name="hibernate.archive.autodetection" value="class" /&gt; &lt;!-- Datasource --&gt; &lt;property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" /&gt; &lt;property name="hibernate.connection.username" value="mobilhm" /&gt; &lt;property name="hibernate.connection.password" value="mobilhm" /&gt; &lt;property name="hibernate.connection.url" value="jdbc:mysql://localhost/mobilhm" /&gt; &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /&gt; &lt;/properties&gt; &lt;/persistence-unit&gt; </code></pre> <p></p> <p>Some characters in my import.sql is not shown correctly in DB. For example character ü becomes ü in db. Default charset in mysql is utf-8 and I'm creating tables like </p> <pre><code>CREATE TABLE doctor (doctorId int unsigned NOT NULL AUTO_INCREMENT, name varchar(45) NOT NULL, surname varchar(45) NOT NULL, PRIMARY KEY (doctorId)) ENGINE=InnoDB DEFAULT CHARSET=utf8; </code></pre> <p>It is weird that if I import using Mysql import/export manager data is correct but using hibernate.hbm2ddl.auto=create makes characters corrupted.</p> <p>How can I solve this?</p> <p>Edit: Also I've tried adding </p> <pre><code>&lt;property name="hibernate.connection.useUnicode" value="true" /&gt; &lt;property name="hibernate.connection.characterEncoding" value="UTF-8" /&gt; &lt;property name="hibernate.connection.charSet" value="UTF-8" /&gt; </code></pre> <p>to persistence.xml. But it didn't help.</p> <p>Fix: I've solved it eventually. I'm using Tomcat and that is the point of corruption not hibernate or mysql. I've started it with set JAVA_OPTS=-Dfile.encoding=UTF-8 command and my problem goes away.</p> <p>The title of question became misleading now. Sorry for that.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload