Friday 4 July 2008

error : hibernate with Data type in DB

* Error Message
"java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date"

You might have data type column in DB table and read it with hibernate.
In this case , you should update "dataSource.xml" file
Add " p:zeroDateTimeBehavior="convertToNull" "

=== Pull xml file =====
[?xml version="1.0" encoding="UTF-8"?]

[beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
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-2.5.xsd"]

[bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=euckr&zeroDateTimeBehavior=convertToNull"
p:username="root" p:password="1111"]

[/beans]

No comments: