Tony
Tony

Reputation: 3805

Hibernate and cyrillic

I want to add some russian text into table. It works fine if I will do using MySQL, but not Hibernate. This makes my text look ????:

public void addHeadHunter(String city, Integer salary) {

        Session session = null;

        session = this.sessionFactory.getCurrentSession();
        Query query = session
                .createSQLQuery(
                        "INSERT INTO headhunter VALUES(NULL,:city,:salary,NULL)")
                .setString("city", city).setInteger("salary", salary);
        int updated = query.executeUpdate();
    }

What's wrong, comrades?

Upvotes: 4

Views: 1770

Answers (1)

PA001
PA001

Reputation: 451

In your Hibernate config file you'll need to add these properties:

<prop key="hibernate.connection.useUnicode">true</prop>
<prop key="hibernate.connection.characterEncoding">UTF-8</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>

This should allow the use of UTF-8 and support for cyrillic text.

Upvotes: 3

Related Questions