本文主要是介绍Data truncation: Incorrect datetime value: '' for column 'EVENT_DATE' at row 1,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
hibernate执行到session.getTransaction().commit();是报异常:
Data truncation: Incorrect datetime value: '' for column 'EVENT_DATE' at row 1
找了好久,终于找到问题了,记录一下:
我使用的jdk是1.8,hibernate是4.2,mysql-connector是3.1,结果运行下面代码
// 读取hibernate.cfg.xml文件Configuration cfg = new Configuration().configure();// 建立SessionFactorySessionFactory sessionFactory = cfg.buildSessionFactory();Session session = sessionFactory.openSession();session.beginTransaction();session.save(new Event("b very first event!", new Date()));session.save(new Event("A follow up event", new Date()));session.getTransaction().commit();session.close();
Exception in thread "main" org.hibernate.exception.DataException: could not execute statementat org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:71)at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124)at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:189)at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:59)at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3079)at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3521)at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:395)at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:387)at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:303)at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:349)at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1195)at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)at com.struts.user.service.EventService.main(EventService.java:27)
Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '' for column 'EVENT_DATE' at row 1at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2973)at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1129)at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:681)at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1368)at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1283)at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1268)at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:186)... 14 more
查了下说是因为我的mysql-connector的jar包不匹配造成的,于是我将
mysql-connector-java-3.1.14-bin.jar
换成
mysql-connector-java-5.0.8-bin.jar
异常就消失了
这篇关于Data truncation: Incorrect datetime value: '' for column 'EVENT_DATE' at row 1的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!