我使用Hibernate向数据库插入拼音,英文的时候没问题,但是一旦插入中文的就报这种异常:
Exception in thread "main " org.springframework.dao.DataIntegrityViolationException: Hibernate operation: Could not execute JDBC batch update; SQL [insert into user (name, sex, id) values (?, ?, ?)]; null, message from server: "Data too long for column 'name ' at row 1 "; nested exception is java.sql.BatchUpdateException: null, message from server: "Data too long for column 'name ' at row 1 "
java.sql.BatchUpdateException: null, message from server: "Data too long for column 'name ' at row 1 "
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1461)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:394)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:614)
at com.lovo.po.UserDAO.save(UserDAO.java:30)
at com.sxjsuper.test.Test.insert(Test.java:55)
at com.sxjsuper.test.Test. <init> (Test.java:24)
at com.sxjsuper.test.Test.main(Test.java:19)
message from server: "Data too long for column 'name ' at row 1 "; 我知道是对字段name来说太长了,可是我定义的name字段长度是varchar(100),报这种错误我就弄不明白了,谁知道怎么处理啊?
------解决方法--------------------------------------------------------
hibernate3.0的BUG 换3.2就好了
------解决方法--------------------------------------------------------
我用3.0没这毛病啊,你没把插入前的NAME字段值及长度打出来看看啊