0

Im developing a Jee webapp using JPA/Hibernate as ORM framework, PostgreSQL as db, and Tomcat as server. When i start the app i want entitymanager to inject some data in my db. I do that whith

<property name="javax.persistence.sql-load-script-source" value="META-INF/data.sql"/>

in persistence.xml Everything works fine except that i get some bad encoding like "Ardèche" instead of "Ardèche".

My whole project is in utf-8, my database too. I had encoding output problems in Intelli-j terminal with tomcat, that i managed to resolve using -Dfile.encoding=UTF-8 in Help | Edit Custom VM Options. But my data in my db is still wrong, even if in Intelli-J output i get the good result.

If i execute the script straight into pgadmin there is no problem.

I tried everything i could find to solve that, but nothing worked. I probably have conflict in the configuration now, cause i tried too many different stuff. My persistence.xml

        <properties>
            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/DB" />
            <property name="javax.persistence.jdbc.user" value="db" />
            <property name="javax.persistence.jdbc.password" value="" />
            <property name="hibernate.connection.useUnicode" value="true" />
            <property name="hibernate.connection.characterEncoding" value="UTF-8" />
            <property name="hibernate.connection.charSet" value="UTF-8"/>
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.hbm2ddl.auto" value="create" />
            <property name="javax.persistence.sql-load-script-source" value="META-INF/data.sql"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL95Dialect"/>
            <property name="hibernate.connection.autocommit" value="true" />
        </properties>

It's my first message on stackoverflow so i hope i did everything properly ! Thanks !

Alain Duguine
  • 425
  • 7
  • 21
  • Probably the persistence provider causes this, since it does not work only when you are starting up the server (when persistence provided executes the script). Double check it's configuration. Try also https://stackoverflow.com/a/18168698/2000323 Make also sure to use hibernate of versions 5.2.3+, see https://hibernate.atlassian.net/browse/HHH-10972 – Andrey Aug 13 '19 at 08:12

1 Answers1

1

thanks for your answer, i just managed to fix it by adding <property name="hibernate.hbm2ddl.charset_name" value="UTF-8"/> to persistence.xml. I didn't check enough the hibernate doc !

Alain Duguine
  • 425
  • 7
  • 21