-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: hibernate + mysql5 + utf8
PostPosted: Fri Dec 09, 2005 1:14 pm 
Beginner
Beginner

Joined: Wed Jun 08, 2005 10:01 am
Posts: 22
Location: Italy
Hi !
I am using hibernate 3.0.3 to read from a mysql5.0 UTF8 charset database.
I inserted (by phpmyadmin) some russian words in different fields, and then I read them with my application (hibernate+myfaces).
I read cyrillic fonts correctly, but if I write new words and I save them via Hibernate, they are not saved correctly.
I read a lot of ???????? from the database.

How does hibernate manage collation and charsets ?
Should I set any property in the hibernate.cfg.xml ?

Thank you for any help,
Nicola


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 4:36 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Hibernate doe's not use charsets, it reads and writes "java.lang.String". Just use correct charset in HTML and see driver documentation to set correct encoding.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 12:54 pm 
Beginner
Beginner

Joined: Wed Jun 08, 2005 10:01 am
Posts: 22
Location: Italy
baliukas wrote:
Hibernate doe's not use charsets, it reads and writes "java.lang.String". Just use correct charset in HTML and see driver documentation to set correct encoding.


Hi !
Could you be more specific ?
HTML charset is correctly set, do I have to set the encoding just before passing to hibernate the string to be updated ?
Bye
Nic


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 5:13 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Web server and JDBC driver use encodings to conver bytes to characters and characters to bytes for communication with web server and database.
1) Use HTTP header or HTTP meta tags to set encoding for browser.
2) Configure web server to convert strings to the same encoding as browser expects (1 and 2 must use the same encoding, it can be UTF-8)
3) Configure driver or database to use the same encoding use for communication protocol (it can be UTF-8 too)

Configuration is a web server and database specific stuff, it is common to configure encoding in web applications context or global configuration, drivers are configured using JDBC URL parameter and database storage format can be specified at database create time. See your web server and mySQL documentation for details (parameter names), it can be a version specific stuff too. It is not related to hibernte, it has nothing to do with encodings.


Top
 Profile  
 
 Post subject: [SOLVED] UTF8 + HIBERNATE + MYSQL
PostPosted: Fri Mar 24, 2006 8:06 am 
Beginner
Beginner

Joined: Wed Jun 08, 2005 10:01 am
Posts: 22
Location: Italy
Hi !
I have solved adding this 2 line in hibernate.cfg.xml:

Code:
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>


Thank you for your advices,
Nicola


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 11, 2007 11:58 am 
Beginner
Beginner

Joined: Mon Sep 04, 2006 7:18 am
Posts: 45
Hm, I tried adding the two lines to my hibernate.cfg.xml.

The database is UTF-8 and the correct charset are stored in there, but when I try to retrieve the data in a JUnit test and write it out, it is still wrong. Any other ideas?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.