Alexandre H. Tremblay Alexandre H. Tremblay - 7 months ago 39
Java Question

Eclipselink auto creates utf8_unicode_ci

When I start my application, eclipselink is set to auto drop and create the table in the database. I have set it up to create an InnoDB engine using the table creation suffix. However, I would like the text encoding to be utf8_unicode_ci. How can I set up my xml file to achieve that. Right now, it defaults to utf8_general_ci.

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSc...>
<persistence-unit name="Data">

<class>com.core.objects.StandardObject</class>

<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/data" />
<property name="javax.persistence.jdbc.user" value="username" />
<property name="javax.persistence.jdbc.password" value="password" />

<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.ddl-generation.table-creation-suffix" value="engine=InnoDB " />
</properties>
</persistence-unit>
</persistence>

Answer

It's been a while since you have asked this question, anyway I am posting this answer by chance if any one wants to know.

Change your "javax.persistence.jdbc.url" properties value from

"jdbc:mysql://localhost:3306/data"

to

"jdbc:mysql://localhost:3306/data?useUnicode=yes&amp;characterEncoding=UTF-8".

This will enable unicode support for your database.
Hope you had figured it by now ;)