-->
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: "åäö" disappear from my @Lob
PostPosted: Tue Jan 31, 2006 7:15 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:18 am
Posts: 28
Hi.
Perhaps this isn't directly related to Hibernate, but it only happens with @Lobs, so I figured I might get some hints here.
I've got a @Lob String property and when I set the string to something with Swedish charracters "åäö", the String is truncated, starting from the first "å".

Hibernate version: 3.1 and annotations 3.1 beta 8
Database: MySQL 5.0.18 (InnoDB)


You can reproduce it with this code:

Code:
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;

public class Test
{
   public static void main(String argv[])
   {
      AnnotationConfiguration c = new AnnotationConfiguration();
      c.addAnnotatedClass(Foo.class);
      SessionFactory sf = c.buildSessionFactory();

      Foo foo = new Foo();
      foo.bar = "abc, åäö, xyz";

      Session session = sf.openSession();
      Transaction tx = session.beginTransaction();
      session.save(foo);
      tx.commit();
      session.close();
   }

   @Entity
   public static class Foo
   {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      public Long id;

      @Lob
      public String bar;
   }
}




Generated SQL: (seems ok)
From the SQL server log:

Code:
    912 Query       SET NAMES latin1
    912 Query       SET character_set_results = NULL
    912 Query       SHOW VARIABLES
    912 Query       SHOW COLLATION
    912 Query       SET autocommit=1
    912 Query       SET autocommit=0
    912 Query       SHOW VARIABLES LIKE 'tx_isolation'
    912 Prepare     [1]
    912 Query       SHOW CHARACTER SET
    912 Execute     [1] insert into Test$Foo (bar) values ('abc, åäö, xyz')
    912 Query       commit




But when I check the db afterwards, åäö are gone:

Code:
mysql> SELECT * from Test$Foo;
+----+-------+
| id | bar   |
+----+-------+
|  1 | abc,  |
+----+-------+
1 row in set (0.00 sec)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 8:50 am 
Regular
Regular

Joined: Fri Jan 20, 2006 9:38 am
Posts: 61
Location: Notts, UK
There's a "character set" option that you specify somewhere in MySQL, I forget where. I guess that those characters aren't supported in the character set you are currently communicating to MySQL with. Try setting it to ISO8859_1.

I think you can specify this in the database connection URL. Check the MySQL docs.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 9:46 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:18 am
Posts: 28
Thanks, that fixed it. I added this to hibernate.properties:
Code:
hibernate.connection.characterEncoding = utf8


I don't understand why I need UTF-8 though - åäö are all latin1 characters. And I don't understand why it only happened to @Lob, regular Strings (varchar) worked fine. Oh well, it all works now. :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 10:04 am 
Regular
Regular

Joined: Fri Jan 20, 2006 9:38 am
Posts: 61
Location: Notts, UK
Whoop-de-doo! I got a credit! (even though I got the actual charset wrong)

I was wondering how I was going to build them up considering I'm a total Hibernate newbie!


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.