Error with MySQL DATETIME ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp

When I started work with MySQL from Hibernate I got exceptions with approximate content :
… ‘0000-00-00 00:00:00’ …. can not be represented as java.sql.Timestamp

My solution for this bug was following :
As I used bean datasource :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<beans
   xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

 
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <!-- <value>/WEB-INF/database/database.properties</value> -->
        <value>/META-INF/spring/database/database.properties</value>
    </property>
</bean>
 
<bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}?zeroDateTimeBehavior=convertToNull" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
</bean>
 
</beans>

I added into property URL :

Because I added also in bean id=”sessionFactory” such property :

1
2
3
4
5
6
7
        <property name="hibernateProperties">
            <props>
.....
                <!--  -->
                <prop key="hibernate.connection.zeroDateTimeBehavior">convertToNull</prop>
            </props>
        </property>

that does not help to resolve exception.