-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem creating object with unicode char (field too long)
PostPosted: Mon Jan 22, 2007 9:54 pm 
Newbie

Joined: Sat Nov 18, 2006 2:21 pm
Posts: 6
Location: California
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.1GA

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

MysqlDataTruncation: Data truncation: Data too long for column 'title' at row 1
Stack:
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2973)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1129)
com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:681)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1368)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1283)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1268)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2200)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2590)
org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)


Name and version of the database you are using:MySQL 5.0.24

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

I have created an object with a VARCHAR(255) this field is called title. If I create an object and set title with a string that contains a unicode character (for instance with a value of 65533), I get the exception above.

I have the following jdbc url:

jdbc:mysql://localhost/ptcms?autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8

And I am setting the following hibernate properties:

dbconfig.hibernate.connection.useUnicode=true
dbconfig.hibernate.connection.characterEncoding=utf8
dbconfig.hibernate.connnection.charSet=utf8

I have also tried:
dbconfig.hibernate.connection.useUnicode=true
dbconfig.hibernate.connection.characterEncoding=UTF-8
dbconfig.hibernate.connnection.charSet=UTF-8

I am using the Mysql 3.14 connector and this is all on a mac. I have also tried this on a linux box with the same effect. I have even single stepped through the jdbc driver and see it use UTF-8 as the encoder when it ultimately asks for the bytes from the string as it prepares the packet to send over the wire to the mysql server.

If I look at the character set for this column it is "western european", I am using hibernate to auto create the tables so I have no idea how to make it choose another encoding as default....and not even sure that it matters.

UPDATE
=====
I just updated to 5.1.14 beta of the mysql server and now the error is changed (seemed there was a bug in what was being reported). It now says:

SQLException: Incorrect string value: '\xEA\x82\xA0 wi...' for column 'title' at row 1

Now in the db this column is not a utf8 encoded column, could this be the reason? If so, how do you declare the encoding type for a field in hibernate?
Any clues welcome.

Cheers

Chris


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

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.