Jul 02 2008

Persist special Characters in DB using Hibernate

von Daniel unter Java

Hibernate is really a big advantage when developers want to persist and work with whole objects. I work with Hibernate since a few months and the benefits are great. Clear Code, great Performance and nice options for me as developer.

But if you try to persist data with various special chars like the german ‘Umaute’ oder just the € char it really pissed me off!

The Hibernate Documentation gives a small hint that there is a property called “hibernate.connection.charSet” that can handle the Hibernate Connecton CharSet. I try to set this property but it won’t work for me.

After some really frustrating hours i find a Solution that works – for me.
Try to add the following Paramets to the connection.Url property in the hibernate.cfg.xml like this:

<property name=”connection.url”>
jdbc:mysql://localhost/foo?useUnicode=true&
ConnectionCollation=utf8_general_ci&
characterSetResults=utf8
</property>

Hope it work for you too!

Keine Kommentare bisher

Trackback URI | Comments RSS

Lass einen Kommentar da