-->
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.  [ 12 posts ] 
Author Message
 Post subject: TEXT fields - random (?) characters replaced with gibberish
PostPosted: Tue May 03, 2005 5:36 pm 
Beginner
Beginner

Joined: Fri Apr 29, 2005 10:57 pm
Posts: 41
Hibernate version: 3.0

Basically after I made switch from my old ways (using prepared statements and SQL statements) to Hibernate, my client pointed out a problem:

Whenever I would do HibernateUtil.update( myclass ), where I only changed some INT value, the TEXT field containing description of an object would (apparently) also be updated (even though it wasn't changed) and some gibberish started to appear in text.

When I say gibberish I mean random out-of-normal-range ascii characters (like As with dots on top and stuff), and they seemed to appear in random spots (but normally as a first letter in the sentence).

I have no idea what could be causing this (I doubt it's encodings, since most of the stuff stays fine), and I doubt my client is putting crap in there just to annoy me.

Anybody dealt with anything like this before?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 6:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
really sounds like encoding issues .... hibernate detects a change in the contents.

are you sure your browser-client/servlet-server is doing encoding properly ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: !
PostPosted: Wed May 04, 2005 1:54 am 
Beginner
Beginner

Joined: Fri Apr 29, 2005 10:57 pm
Posts: 41
Well, my tables are all UTF-8, but I didn't specify UTF-8 in my DB URL connection (becuase Hibernate was giving me crap about it, I think it had something to do with the &, I didn't really look into it)...

But how can it be encoding issues if everything else is fine?... Here, let me try to type something in Russian...

OUCH!!!!

The Russian is turned into Gibberish, and the page is encoded in UTF-8. Which means that the bridge between Hibernate and DB messes up the encoding...

But that still woudln't explain why English encoding is messed up... Especially in such wierd spots. Although, who knows..

Then the question is - how do I specify &encoding=UTF-8 ?

By the way, I just bought the Hibernate in Action book today (have your donuts, Gaving King and Christian Bauer, hope you don't choke ;)), so I'll look in it as well.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 2:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I promise you that hibernate is not messing with any encoding settings or contents AT ALL - its all pure passthrough to the db.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 3:46 am 
Regular
Regular

Joined: Tue Nov 23, 2004 7:42 am
Posts: 82
Location: London, England
What database are you using?

Are you sure the text you're putting in is UTF-8 encoded?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 5:27 am 
Beginner
Beginner

Joined: Fri Apr 29, 2005 10:57 pm
Posts: 41
You promise huh? But do you swear on your mother? :)

In the past I had a bit similar experience (with the exception of random gibberish appearing) where I had the input page in UTF-8, the output page in UTF-8, and the db fields in UTF-8.

BUT! I didn't specify encoding=UTF-8 as a part of the URL, and as a result nothing worked. From that point on I simply added that string as a parameter to the DB URL, and everything worked just fine. When I tried doing the same with Hibernate, i got some error about improperly formatted XML file.. I didn't really look into it though.

But that still wouldn't explain why random crap appears..

Although:

1) THe text is stored in DB in UTF-8

2) Over our non-UTF-8 connection, the client retrieves it, but the page is UTF-8, so it converts some characters in the text field (but leaves ENglish same since it's the same char values in UTF-8 or ascii)

3) Update method is called (every single property is reset beforehand - we're in the "modify object" page)

4) Hibernate sees that what was in database (normal UTF-8) is different from what the user's giving us (UTF-8 filtered through ascii and filtered back into UTF-8), and as a reult it changes it in the database. So, now we have UTF-8 in the database, which has been crippled by ascii..

That's my guess, I guess I'll have to figure out how to append the encoding thing on the DB URL...

Any clues, mates?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 5:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I swear yes.

what db are you running on ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 5:33 am 
Regular
Regular

Joined: Tue Nov 23, 2004 7:42 am
Posts: 82
Location: London, England
Seriously! Dude! What database are you using?

I'm wondering if you're using MySQL. I've had problems with MySQL and UTF-8 and tracked it down to the driver. It seems to me that the Connector/J 3.1 series is broken where the 3.0 series isn't.

And that thing with the improperly formatted XML file: I bet you added '&encoding=UTF-8'. The ampersand breaks XML because it needs to be terminated with a semi-colon. Try this '&encoding=UTF-8'.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 2:17 pm 
Beginner
Beginner

Joined: Fri Apr 29, 2005 10:57 pm
Posts: 41
Hey!

I'm on MySQL 4.1

And yeah I'll try the older JConnector and the encoding URL as soon as I finish eating my baby back ribs with El Much Picante sauce. Mmm.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 3:54 am 
Regular
Regular

Joined: Tue Nov 23, 2004 7:42 am
Posts: 82
Location: London, England
You probably won't need to fiddle with the URL as the connector can determine which encoding to use.

The problem we had was slightly different in that the driver would drop all information after encountering a UTF-8 character.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 1:04 am 
Beginner
Beginner

Joined: Fri Apr 29, 2005 10:57 pm
Posts: 41
YUP!

It was the missing UTF-8 part in the URL, not the driver...

Basically, I appended the following to my URL:

Quote:
?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8


And now everything works like a charm!

No gibberish, and all languages supported! (I checked Russian)


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 3:32 am 
Regular
Regular

Joined: Tue Nov 23, 2004 7:42 am
Posts: 82
Location: London, England
Hmm. I might try the same thing then, just to be sure. It's weird because I'd tried that same URL and had no luck with it.

Oh well. Glad you're sorted.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 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.