<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Martin Ahrer - Together we&#039;ll make IT &#187; Oracle</title>
	<atom:link href="http://www.martinahrer.at/tag/oracle/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.martinahrer.at</link>
	<description>Java Enterprise Softwareentwicklung und Consulting</description>
	<lastBuildDate>Sun, 11 Dec 2011 16:19:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<meta name="generator" content="deSignum 0.8.1" />
		<item>
		<title>Oracle 9.2+ JDBC Driver DATE type problem</title>
		<link>http://www.martinahrer.at/2007/12/27/oracle-92-jdbc-driver-date-type-problem/</link>
		<comments>http://www.martinahrer.at/2007/12/27/oracle-92-jdbc-driver-date-type-problem/#comments</comments>
		<pubDate>Thu, 27 Dec 2007 17:04:08 +0000</pubDate>
		<dc:creator>Martin Ahrer</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://www.martinahrer.at/2007/12/27/oracle-92-jdbc-driver-date-type-problem/</guid>
		<description><![CDATA[With Oracle 9.2 some changes regarding the DATE type and the new TIMESTAMP type were introduced. These are causing problems with the JDBC driver when an application is expecting a DATE column to contain time information. These issues and a workaround are discussed in this article from Oracle. This article proposes a few workarounds that [...]]]></description>
			<content:encoded><![CDATA[<p>With Oracle 9.2 some changes regarding the DATE type and the new TIMESTAMP type were introduced. These are causing problems with the JDBC driver when an application is expecting a DATE column to contain time information.  These issues and a workaround are discussed in this <a href="http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq_0.htm#08_01">article</a> from Oracle.</p>
<p>This article proposes a few workarounds that you might be able to apply or not. Today I encountered a case that was troubling me for a while.</p>
<p>I&#8217;m using Hibernate 3.2.5.ga to map a class to some legacy table containing a DATE column holding date + time information. The property mapping looks as simple as <code>&lt;property name="timestamp" column= "MESSAGE_TIMESTAMP"/ &gt;</code>.</p>
<p>I have configured Hibernate with <code>hibernate.hbm2ddl.auto=validate</code> so my mapping files are checked against database metadata. As a result Hibernate would throw an exception at me telling that it can&#8217;t match the column type with the POJO property type.</p>
<pre lang="text">
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/context-web.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Wrong column type: COMM_MSGDT, expected: timestamp
Caused by: org.hibernate.HibernateException: Wrong column type: COMM_MSGDT, expected: timestamp
	at org.hibernate.mapping.Table.validateColumns(Table.java:261)
...
</pre>
<p>If you don&#8217;t need time information you can get around this execption by tweaking the type information for the property mapping (<code>&lt;property name="timestamp" column="MESSAGE_TIMESTAMP" type="date"/&gt;</code>) otherwise if time is required then you are in trouble!</p>
<p>The Oracle article above is suggesting to set a system property (as a JVM start parameter) which is kind of difficult to handle during deployment. So I was investigating the other option which is to set the connection property (<code>oracle.jdbc.V8Compatible=true</code>) for the Oracle JDBC driver, this option would allow a deployment configuration that is working &#8220;out-of-the-box&#8221;. Reading the Tomcat documentation on how to configure a <a href="http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html#Database%20Connection%20Pool%20(DBCP)%20Configurations">JNDI DataSource</a> led me to the <a href="http://commons.apache.org/dbcp/configuration.html">DBCP documentation</a> that is explaining this thoroughly.</p>
<p>I&#8217;m using a Tomcat managed DataSource. So I&#8217;m having a <code>META-INF/context.xml</code> file to set up the DataSource. To fix the type problem just add the property <code>connectionProperties</code>.</p>
<pre lang="xml">
<resource name="jdbc/dsname" auth="Container" type="javax.sql.DataSource"
	driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@host:1526:SID" username="user"
	password="password" maxActive="20" maxIdle="10" maxWait="-1"
	connectionProperties="oracle.jdbc.V8Compatible=true;"
/>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.martinahrer.at/2007/12/27/oracle-92-jdbc-driver-date-type-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

