Value ‘0000-00-00’ can not be represented as java.sql.Date

If you get "javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Value '0000-00-00' can not be represented as java.sql.Date" error
or just "Value '0000-00-00' can not be represented as java.sql.Date" error,
you have to add "zeroDateTimeBehavior=convertToNull" to your connection URI.
(Source: https://dev.mysql.com/doc/refman/5.0/en/connector-j-installing-upgrading.html)

    Solutions:

  1. In jboss admin console, open “Profile > Connector > Datasources > Properties” and add this property:
    key: zeroDateTimeBehavior – value: convertToNull
    or
    Open “jboss-as-x.x.x.Final\standalone\configuration\standalone.xml” and add

    <connection-property name="zeroDateTimeBehavior">
    	convertToNull
    </connection-property>
  2. You can use this JDBC URL directly in your datasource configuration:
    jdbc:mysql://yourserver:3306/yourdatabase?zeroDateTimeBehavior=convertToNull
  3. Add this to hibernate.cfg.xml:
    <property name="hibernate.connection.zeroDateTimeBehavior">convertToNull</property>
  4. In hibernate.properties:
    hibernate.connection.zeroDateTimeBehavior=convertToNull
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s