0

i add two field to my domain Class ContentSequence : lastUpdated,dateCreated ,which is updated automatically by GORM.

After running the application again , i try to get a record :

ContentSequence.get(1);

Unfortunately, i get the following in console of Web interface : org.springframework.dao.TransientDataAccessResourceException: Hibernate operation: could not load an entity: [com.abdennour.content.ContentSequence#200]; SQL [select contentseq0_.id as id17_0_, contentseq0_.version as version17_0_, contentseq0_.chapter_id as chapter3_17_0_, contentseq0_.date_created as date4_17_0_, contentseq0_.difficulty as difficulty17_0_, contentseq0_.last_updated as last6_17_0_, contentseq0_.level_id as level7_17_0_, contentseq0_.name as name17_0_, contentseq0_.other as other17_0_, contentseq0_.owner_id as owner10_17_0_, contentseq0_.subject_id as subject11_17_0_, contentseq0_.type as type17_0_ from content_sequence contentseq0_ where contentseq0_.id=?]; Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp; nested exception is java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

and in terminal , i get :

util.JDBCExceptionReporter Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp 
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254

3 Answers3

3

Error -> Cannot convert value ’0000-00-00 00:00:00′ from column XX to TIMESTAMP Reason > 0000-00-00 00:00:00 is outside the range of a TIMESTAMP value (in fact, it won't work with a DATE field either). Solution -> modify JDBC option jdbc:mysql://localhost/test?zeroDateTimeBehavior=convertToNull

yama
  • 31
  • 1
0

I do manually a queries SQL to update the value of Date field since Timestamp has minimum

UPDATE content_sequence
SET date_created = '2013-08-08 00:00:00';
    UPDATE content_sequence
SET last_updated = '2013-08-08 00:00:00';

and now, it is work.

Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254
0

Also try zeroDateTimeBehavior

  • zeroDateTimeBehavior

What should happen when the driver encounters DATETIME values that are composed entirely of zeros (used by MySQL to represent invalid dates)? Valid values are "EXCEPTION", "ROUND" and "CONVERT_TO_NULL".

Default Value EXCEPTION
Since Version 3.1.4

connector-j/5.1

connector-j/8.0

handling-datetime-values-0000-00-00-000000-in-jdbc

MySQL Error, "java.sql.SQLException: Value ''0000-00-00'' can not be represented as java.sql.Date"

MySQL: Value '0000-00-00' can not be represented as java.sql.Timestamp

Nick Dong
  • 3,638
  • 8
  • 47
  • 84