Running the Hibernate Application with Oracle

I am using the default database that comes with the Oracle implementation.
The username/password for this database is scott/tiger and the SID I have presumed is mattiz (This is set during Oracle installation.).
I changed only one file in the application described in the previous blog, that is, spring-servlet.xml. http://cuppajavamattiz.com/2007/09/15/a-simple-spring-hibernate-example/ I also copied the oracle driver ojdbc14.zip to server/default/lib. (The driver can be got from the Oracle website.)
Change is only to one configuration file: spring-servlet.xml.
Here is the source for the modified spring-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!-- - Application context definition for "springapp" DispatcherServlet. -->
<beans>
	<!-- Business Layer beans definition -->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="viewClass">
			<value>org.springframework.web.servlet.view.JstlView</value>
		</property>
	</bean>
	<!-- Oracle DataSource Definition -->
	<bean id="dataSourceOracle" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
		<property name="url" value="jdbc:oracle:thin:@localhost:1521:mattiz" />
		<property name="username" value="scott" />
		<property name="password" value="tiger" />
	</bean>
	<!-- Hibernate SessionFactory Definition -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="mappingJarLocations">
			<value>WEB-INF/lib/mattiz.jar</value>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.OracleDialect
				</prop>
				<prop key="hibernate.show_sql">true</prop>
			</props>
		</property>
		<property name="dataSource">
			<ref local="dataSourceOracle" />
		</property>
	</bean>
	<!-- Hibernate Template Defintion -->
	<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
		<property name="sessionFactory">
			<ref local="sessionFactory" />
		</property>
		<property name="cacheQueries" value="false" />
		<property name="jdbcExceptionTranslator">
			<ref local="jdbcExceptionTranslator" />
		</property>
	</bean>
	<bean id="jdbcExceptionTranslator"
		class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
		<property name="dataSource">
			<ref local="dataSourceOracle" />
		</property>
	</bean>
</beans>

Get source code here Hibernate_with_Oracle

About cuppajavamattiz
Matty Jacob - Avid technical blogger with interests in J2EE, Web Application Servers, Web frameworks, Open source libraries, Relational Databases, Web Services, Source control repositories, ETL, IDE Tools and related technologies.

Comments are closed.

%d bloggers like this: