Development environment:
- Spring 4.2x
- Hibernate 4.3.11
- Tomcat 8 server
- MySQL 5.4
Before make the change to Hibernate there was no problem inserting, retrieving and displaying the characters. However after making the change in my DAO to use Hibernate oddly i can't seem to insert the correct character in to the MySQL DB.
I have made sure that MySQL Schema can indeed save UTF-8 Character set by using query "INSERT INTO spring_normalize
.offers
(text
, users_username
) VALUES ('ölm', 'lalalal');" the output on the index.jsp is correct.
I modified my hibernate config
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.connection.useUnicode">true</prop><!-- added -->
<prop key="hibernate.connection.characterEncoding">UTF-8</prop><!-- added -->
<prop key="hibernate.connection.charSet">UTF-8</prop><!-- added -->
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.caveofprogramming.pring.web.dao</value>
</list>
</property>
</bean>
This doesn't seem to work
Check list:
- DB schema is set to utf8 - utf8_unicode_ci.
- Hibernat config add charSet to UTF-8.
- jsp page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8
- I have also added filter as this post suggested... Spring MVC UTF-8 Encoding
* Update * this is my bean and DAO
Form
<sf:form method="POST" action="${pageContext.request.contextPath}/docreate" commandName="offer">
<sf:input type="text" path="id" name="id" readonly="true" />
<label for="text">Text</label>
<sf:textarea id="text" name="text" row="3" path="text"></sf:textarea>
<sf:errors path="text" cssClass="error"></sf:errors>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<input type="submit" value="Submit">
</sf:form>
Offer
@Entity
@Table(name="offers")
public class Offer{
@Id
private int id;
private String text;
getIn(){}
.....
}
OfferDao
public class OfferDao{
@Autowired
private SessionFactory sessionFactory;
public Session currentSession(){
return sessionFactory.getCurrentSession();
}
public boolean create(Offer offer){
int hiberReturn =(int) currentSession().save(offer);
return hiberReturn >= 0;
}
}
Anyone who can help is much much appreciated... really.. many many thanks