Can someone please help solve this.
I have a maven 3 project with project.build.sourceEncoding set to UTF-8 and my netbeans IDE is set to UTF-8 encoding.
Using hibernate 4 I have several String entities that need to be nvarchar, eg:
@Column(length = 255, columnDefinition = "nvarchar(255)")
private String title;
Against our MSSQLServer databases these work correctly as intended handling accents, umlauts and macrons, the problem is in my unit test framework using the H2 in-memory database the accents and macrons do not work as intended.
Spring config contains:
<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driverClass" value="org.h2.Driver"/>
<property name="url" value="jdbc:h2:mem:sqr;DB_CLOSE_DELAY=-1"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" >
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.hbm2ddl.import_files">test-import.sql</prop>
</props>
</property>
</bean>
The test-import.sql is UTF-8 encoded and contains accents, unlauts, and macrons, and loads fine but when unit testing the retrieved values the assertions fail due to the encoding problem, for example:
junit.framework.AssertionFailedError:
Expected: is "Produce a resumé"
got: "Produce a resumé"
As this works fine live but not when using H2 I can only think that it's either the H2 database not handling the encoding or the hibernate import not handling it.
Does H2 not support unicode in this manner or is there some hidden property I have missed?
Help appreciated.