-->
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.  [ 4 posts ] 
Author Message
 Post subject: Character Encoding Problem in Hibernate
PostPosted: Thu Jun 15, 2006 7:22 am 
Newbie

Joined: Thu Jun 15, 2006 7:02 am
Posts: 1
Hi All..
We have some difficulty in storing UTF-8 characters in out Java App (Struts-Hibernate-MYSQL).The request charset and the DB charset are set correcly to UTF-8.

When a user enters UTF-8 charcters,they are stored properly in the DB.
While retrieving from the DB thru Hibernate,the collection seems to ignore UTF-8 charcters and are rendered wrongly on the UI.
If this value is used to store back in the DB,the UTF-8 characters are lost.

Has one faced this problem earlier too? We are using Hibernate 3.0
Is there any way to specify Hibernate to use UTF-8 encoding?

Thanx
Vijay


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

Joined: Mon Sep 04, 2006 7:18 am
Posts: 45
I have exactly the same problem.

Any solution?


Top
 Profile  
 
 Post subject: Re: Character Encoding Problem in Hibernate
PostPosted: Mon Jun 25, 2012 7:11 am 
Newbie

Joined: Mon Jun 25, 2012 6:57 am
Posts: 1
Hi,

I am also facing the same problem.

My Oracle database table has Japanese and Chinese characters stored in it. But when I retrieve the data, some garbage characters is what I get. I tried the below 2 configurations in hibernate configuration, but didnt worked

1)
<hibernate-configuration>
<session-factory>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">ISO-8859-1</property>
<property name="connection.charSet">ISO-8859-1</property>

2)
<hibernate-configuration>
<session-factory>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
<property name="connection.charSet">UTF-8</property>

Can somebody please tell me the exact configurations to read Japanese characters.


Top
 Profile  
 
 Post subject: Re: Character Encoding Problem in Hibernate
PostPosted: Wed Jun 27, 2012 2:06 am 
Beginner
Beginner

Joined: Wed Sep 30, 2009 5:29 am
Posts: 29
spvijay wrote:
Hi All..
We have some difficulty in storing UTF-8 characters in out Java App (Struts-Hibernate-MYSQL).The request charset and the DB charset are set correcly to UTF-8.


You don't seem to be paying attention the to charset used by the web page. Your UTF-8 characters may be received by the browser in UTF-8, but that doesn't mean they are rendered as UTF-8, or sent back to the server as UTF-8.

For example:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

It's possible to intiate a request via xhr specifying charset in the headers that doesn't match your current page's charset, which will lead to trouble.

spvijay wrote:
When a user enters UTF-8 charcters,they are stored properly in the DB.
While retrieving from the DB thru Hibernate,the collection seems to ignore UTF-8 charcters and are rendered wrongly on the UI.
If this value is used to store back in the DB,the UTF-8 characters are lost.


That's pretty weird. I can't think why a user entering data might produce different encoding to the page being populated with data and that data saved, unless your UI components are somehow mangling the data. Are you using plain HTML <input> tags, or some Javascript client library that might be performing some re-encoding? How exactly is your request for data initiated, and the result put into the UI?

I had lots of trouble recently with a latin-1 database, read by a PHP script, which was called by a Java app server and fed to a web browser, and then the whole thing again in reverse. For you, Java itself should be able to deal with UTF-8 transparently, if all your data is in that encoding you won't have trouble at that layer. I ended up having to use "byte[] utf8bytes = String.getBytes(targetCharset)" and "String targetversion = new String(utf8bytes, targetCharset)" .. but in your case, if your data is clearly getting to and from the UI correctly, the encoding trouble must be in your web layer and nothing to do with your Java server.

Nick


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.