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
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
解决方案 »
- 通过JDBC方式查询数据库生成数据效率低,请问下问题出在什么地方或者有什么解决方案?
- 关于正则表达式
- eclipse 打不开 在线等!!
- 用MyEclipse6连接mysql数据库时出现Communications link failure这个错误,请高手帮忙解答一下!
- baseFormController 的执行过程是怎么样的啊?
- 关于hibernate使用存储过程的问题
- Ant增量编译
- 如何为 struts+spring+hibernate 做测试!
- 有关apache xml-rpc中传递struct的问题
- 应用服务器与WEB SERVER的区别
- 请问如何从连接池获取IP,用户名?
- 接口不实现方法,但我却在程序中可以调用接口的方法,这是为什么
17:36:35,062 ERROR AbstractFlushingEventListener:324 - Could not synchronize database state with session 根据你提供的信息 检查2个地方1 你的CDID里的值已经超出了你的数据库里定义的长度2 如果不是上面的问题 请检查你的spring事务管理对不对