Posts

Showing posts from December, 2010

Hibernate + Spring + MySql: Cannot convert value '0000-00-00 00:00:00' from column X to TIMESTAMP

Image
When I was trying to load an Hibernate object, I received the following error: nested exception is java.sql.SQLException: Cannot convert value '0000-00-00' from column 4 to TIMESTAMP. at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQL This exception means that the column "X" has an invalid date "0000-00-00 00:00:00" According to http://bugs.mysql.com/bug.php?id=13030 "Datetimes with all-zero components ('0000-00-00 ...') - These values can not represented reliably in Java. Connector/J 3.0.x always converted them to NULL when being read from a ResultSet. When working with MySQL over JDBC and the driver encounters a zero DATE, TIME, or DATETIME value (that is, e.g, ‚0000–00–00‘ for DATE), this exception is thrown. This can be handled by adding the JDBC Parameter: zeroDateTimeBehavior=convertToNull to your JDBC connection. url=jdbc:mysql://localhost/test?connectTimeout=60000&autoReconnect=true&ze