I have a Mysql table with DATE column , default '0000-00-00'. If I try to call, for instance,
em.find(MyTable.class,pk_value);
and it happens to be a record in database with default date value '0000-00-00', an exception is thrown(
"java.sql.SQLException: Value ... cannot be represented as java.sql.Date". The same error happens for DateTime columns with default '0000-00-00 00:00:00'.
Is it any way to tell EntityManager that such values are ok ?
Thanks.
What helps is setting JDBC driver's zeroDateTimeBehavior property to convertToNull.
See http://ondra.zizka.cz/stranky/programovani/java/index.texy (look for "SQLException for zero DATETIME or TIMESTAMP column? Use zeroDateTimeBehavior").
jdbc:mysql://localhost/test?zeroDateTimeBehavior=convertToNull
By setting the zeroDateTimeBehavior=convertToNull
property we can avoid this problem. For details please check this link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With