beautypg.com

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

Page 241

background image



${jdbc.password}




${jdbc.catalog}


${jdbc.schema}




class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">


Employee.hbm.xml




org.hibernate.dialect.SqlmxDialect
true











class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">


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

This manual is related to the following products: