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