Modifying the employeedao.java file – HP Integrity NonStop J-Series User Manual

Page 241

Advertising
background image

</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
<property name="connectionProperties">
<props>
<prop key="catalog">
${jdbc.catalog}
</prop>
<prop key="schema">
${jdbc.schema}
</prop>
</props>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>Employee.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SqlmxDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<bean id="empdao" class="com.hp.empinfo.service.EmployeeDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="/WEB-INF/jdbc.properties"/>
</bean>
</beans>

Modifying the EmployeeDao.java File

Modify the EmployeeDao.java file (under the com.hp.empinfo.service package), to
change the JDBC queries to Hibernate queries for the insert, delete, and retrieve operations, using
the following steps:

1.

Instantiate the Hibernate SessionFactory as shown:

private SessionFactory sessionFactory;

public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}

2.

Add the following import statements to enable the Hibernate SessionFactory:

import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;

3.

Change all the database queries to use the Hibernate SessionFactory.

After modification, the EmployeeDao.java file should appear as:

package com.hp.empinfo.service;

import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import com.hp.empinfo.service;

Integrating Hibernate into Spring

241

Advertising
This manual is related to the following products: