Mock tests, Interview questions, Tutorials and Tech news
 
 
Home > Programming / tutorials > Hibernate: SQLException: Cannot convert value ‘0000-00-00′ from column to TIMESTAMP.

Hibernate: SQLException: Cannot convert value ‘0000-00-00′ from column to TIMESTAMP.

  Recently when fetching row using Hibernate I got following Exception:

Caused by: java.sql.SQLException: Cannot convert value ‘0000-00-00′ from column 5 to TIMESTAMP.

   This I got when calling findByExample method on Hibernate’s EntityManager.

   The cause for this was a 0 value in the updated_date column of the table at db. The update_date column is of type DATE. Recently I had imported some data to this table and all the columns had ‘0000-00-00’ as updated_date. Clearly MYSQL was failing to convert the date value to timestamp.

   Solution for this was to append zeroDateTimeBehavior=convertToNull in the connection URL.

db.url=jdbc:mysql://localhost:3306/mydb?autoReconnect=true&zeroDateTimeBehavior=convertToNull

This is to enable the driver to handle the DATETIME values that consist of zeroes. This solved my problem.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Mixx
  • Google Bookmarks
  • IndianPad
  • Reddit
  1. October 25th, 2009 at 05:19 | #1

    And you solved my day ;)
    Thank you :)

  1. No trackbacks yet.
Get Adobe Flash playerPlugin by wpburn.com wordpress themes