2

Through an extern properties file url is specified as the following jdbc:mariadb://xxxxx:3306/xxxxx?zeroDateTimeBehavior=convertToNull

The connection works fine and am able to query the DB. Through hibernate I made an entity that is mapped to a table with a date column. When no date was specified a zero date was inserted by default (0000-00-00). When I get the date out of an entity with a zero date it gives a date that shows as 00002-10-02 cause java date cant handle a year or month/day that is zero.

The zeroDateTimeBehavior=convertToNull is supposed to handle this and give back null value so i can properly handle these situations and not erroneously give back a completely wrong date.

Ive read through about 50 forum topics but was not able to find a solution. Let me know if I can provide more information. Thanks.

Visker
  • 21
  • 1
  • 2
  • 1
    Hi I can see you are new here, please update the question to include a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Strazan Apr 29 '19 at 14:05
  • 1
    This would suggest you are using a different connection and connection string when using Hibernate. – Mark Rotteveel Apr 30 '19 at 11:33

1 Answers1

5

Try using zeroDateTimeBehavior=CONVERT_TO_NULL, that works for me.

I also found this from the docs: https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-configuration-properties.html

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: EXCEPTION

Since version: 3.1.4
Jose Jurado
  • 301
  • 4
  • 7