Reputation: 191
I am having a problem storing unicode characters to Oracle 11g using JPA. When I store a unicode string to DB using this (someTranslation is an object containing unicode strings).
someTranslation.setMessage("文字"); //literally means characters
em.persist(someTranslation);
The string is then displayed as an inverted '?' ("¿")
When I manually fix a corrupted string in DB using SQLDeveloper, the characters are then displayed correctly as what it is intended.
I've searched a bit that when using MySQL, only a small modification is needed to correct this. I feel I am having the same problem with that post except I am using oracle 11g instead. Do anyone know of a solution for this problem in oracle 11g? Thanks in advance.
Here is my persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<persistence-unit name="cbpejb" transaction-type="JTA">
<class>entity.Translation</class>
<properties>
<property name="openjpa.ConnectionDriverName" value="oracle.jdbc.OracleDriver" />
<property name="openjpa.ConnectionURL" value="jdbc:oracle:thin:@localhost:1521:orcldb" />
<property name="openjpa.ConnectionUserName" value="dev" />
<property name="openjpa.ConnectionPassword" value="dev00" />
<property name="openjpa.jdbc.Schema" value="DEV" />
</properties>
</persistence-unit>
Upvotes: 3
Views: 2103
Reputation: 41113
There are two possible problems:
As of Java itself, the String class supports Unicode, and uses UTF-16 encoding, but your JDBC driver should handle en/decoding
Upvotes: 2