Dec 11 2007

Solving Problems with International (UTF-8) Data using Hibernate, Oracle, and Tomcat

Tag: hibernate, java, oracle, tomcatpmularien @ 6:19 am

Ran into a very interesting issue the other day relating to storing NLS character data in Oracle via Hibernate, running in the Tomcat servlet container. It turns out the solution is not entirely obvious (or well-documented), so I thought I’d jot the important bits down.

NVARCHAR2 is a data type assigned to a column that is used to store NLS data, most generally multi-lingual (UTF-8 or equivalent). This differs from the typical VARCHAR2 data type, which is usually intended for storing data in the local character set (see this for a weak explanation).

In theory you should not have to do anything different in your JDBC-based application to write to an NVARCHAR2 column vs a VARCHAR2 column, since String type in Java is UTF-8.

However, the evil Oracle JDBC driver rears its ugly head again (if you’ve been working with Oracle JDBC for any length of time, you know what I’m talking about ;) )!
Continue reading “Solving Problems with International (UTF-8) Data using Hibernate, Oracle, and Tomcat”


Dec 05 2007

Quick Tip: Convert an Eclipse “General” Project to a Java Project

Tag: eclipse, javapmularien @ 6:57 am

I don’t know how many times I’ve accidentally created a General project instead of a Java project, and it always bugged me that you couldn’t convert from General to Java without starting over.

The quick and easy hack is explained well here. Open the relevant .project file and add the following (note that you don’t need the <natures> element if one is already there):

    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>

It’s too bad you can’t “Add Java Project Nature” from within the Eclipse UI :(

Make sure you do this with the project closed!