public static void main(String[] args){ 
Configuration cfg = new Configuration().configure(); 
SessionFactory factory =cfg.buildSessionFactory(); 
Session session = null; try{ 
session = factory.openSession(); 
session.beginTransaction(); 
TbNodeInfo tn = new TbNodeInfo(); 
tn.setCname("asaa"); 
tn.setOffnum(false); 
tn.setType(true); 
tn.setNote("北京"); 
tn.setActive("1"); 
tn.setStatus("1"); 
tn.setModTime(new Timestamp(System.currentTimeMillis())); 
session.save(tn); 
session.getTransaction().commit(); }catch(Exception e){ 
e.printStackTrace(); 
session.getTransaction().rollback(); 
} finally{ 
if(session!=null){ 
if(session.isOpen()){ 
session.close(); 



} 17:36:34,796  INFO SettingsFactory:309 - Deleted entity synthetic identifier rollback: disabled 
17:36:34,796  INFO SettingsFactory:324 - Default entity-mode: pojo 
17:36:34,796  INFO SettingsFactory:328 - Named query checking : enabled 
17:36:34,828  INFO SessionFactoryImpl:193 - building session factory 
17:36:34,984  INFO SessionFactoryObjectFactory:105 - Not binding factory to JNDI, no JNDI name configured 
17:36:35,062  WARN JDBCExceptionReporter:100 - SQL Error: 0, SQLState: 22001 
17:36:35,062 ERROR JDBCExceptionReporter:101 - Data truncation: Data too long for column 'CDNID' at row 1 
17:36:35,062 ERROR AbstractFlushingEventListener:324 - Could not synchronize database state with session 
org.hibernate.exception.DataException: Could not execute JDBC batch update 
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:100) 
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) 
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275) 
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266) 
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167) 
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) 
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50) 
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028) 
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366) 
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137) 
at test.hibernate.Test1.main(Test1.java:33) 
Caused by: java.sql.BatchUpdateException: Data truncation: Data too long for column 'CDNID' at row 1 
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666) 
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082) 
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70) 
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268) 
... 8 more 
org.hibernate.exception.DataException: Could not execute JDBC batch update 
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:100) 
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) 
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275) 
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266) 
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167) 
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) 
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50) 
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028) 
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366) 
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137) 
at test.hibernate.Test1.main(Test1.java:33) 
Caused by: java.sql.BatchUpdateException: Data truncation: Data too long for column 'CDNID' at row 1 
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666) 
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082) 
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70) 
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268) 
... 8 more 

解决方案 »

  1.   

     Data truncation: Data too long for column 'CDNID' at row 1  
    17:36:35,062 ERROR AbstractFlushingEventListener:324 - Could not synchronize database state with session  根据你提供的信息 检查2个地方1 你的CDID里的值已经超出了你的数据库里定义的长度2 如果不是上面的问题 请检查你的spring事务管理对不对
      

  2.   

     Could   not   synchronize   database   state   with   session     一般出现在对一个主键有问题的(也许没有该主键)的数据操作
      

  3.   

    以前遇得到过这情况  “CDID”定义太长了
      

  4.   

    17:36:35,062 ERROR JDBCExceptionReporter:101 - Data truncation: Data too long for column 'CDNID' at row 1 你寫入DB中的數據長度比你DB的字段'CDNID'長了。