I have a web application that uses spring and hibernate. My hibernate session factory is configured in spring as:
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServer2005Dialect</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.example.dslibweb.model</value>
</list>
</property>
</bean>
The data source as:
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="maxActive" value="${jdbc.maxConnections}" />
</bean>
and the properties file for the data source is:
jdbc.username=sa
jdbc.password=***
jdbc.url=jdbc:sqlserver://10.62.0.105:1433;databaseName=example;useUnicode=true;characterEncoding=utf-8
jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.maxConnections=-1
I have a call:
DsActions action = (DsActions) this.hibernateCriteriaCommons.findById(id, new DsActions());
and findById is defined as:
public T findById(String id, Object model) {
return (T) this.sessionFactory.getCurrentSession().get(model.getClass(), id);
}
So I am calling the get method of hibernate session for a specific id and I expect an instance of type DsActions.
All works well when I run it from a local Tomcat instance (run through netbeans).
When I install it on a remote tomcat server, the instance of DsActions seems to have an encoding issue. When retriveing a field of DsActions instance I get question marks (??? ?????? ??????). The text is supposed to be greek characters
I am very confused, I do not understand why in the first case it is working and not in the second.
Note: the data is retrieved by the same database server, so no difference there. The only difference is the machine where the application is running.
Thank you all in advance.
I’m pretty sure that Hibernate retrieves that field correctly, and the problem is in the way you output these characters.
As a quick check you can add a condition such as
f.contains("?")to your code and output its result – it should befalse(if original string doesn’t contain?s, of course).For possible problems in output see Unicode – How to get the characters right?.