Date / Datetime Date and Datetime Columns and Java Persistence

I have a Mysql table with a DATE column, the default is "0000-00-00". If I try to call, for example, em.find(MyTable.class,pk_value); and this happens to be a database record with the default date value of "0000-00-00", an exception is thrown ("java.sql.SQLException: Value ... cannot be represented as java .sql.Date ". The same error occurs for DateTime columns with the default value" 0000-00-00 00:00:00 ".
Can I tell EntityManager that such values ​​are okay? Thanks.

+5
source share
3 answers

zeroDateTimeBehavior JDBC ToNull.

. http://ondra.zizka.cz/stranky/programovani/java/index.texy ( "SQLException DATETIME TIMESTAMP? zeroDateTimeBehavior" ).

jdbc:mysql://localhost/test?zeroDateTimeBehavior=convertToNull

+7

zeroDateTimeBehavior=convertToNull, . . .

+1

How to change ZERO dates to null.

0
source

All Articles