beautypg.com

Modifying the employeedao.java file, Modifying the, Employeedao.java – HP Integrity NonStop H-Series User Manual

Page 406: File

background image

${jdbc.schema}



class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">






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


Modifying the

EmployeeDao.java

File

Modify the

EmployeeDao.java

file, to use JPA in place of Hibernate for the insert, delete, and

retrieve operations.

To modify the

EmployeeDao.java

file, complete the following steps:

1.

Instantiate the JPA as shown:

private EntityManagerFactory entityManagerFactory;

public void setEntityManagerFactory(
EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}

2.

Add the following

import

statements to enable the JPA

EntityManagerFactory

and to

use the

EntityEmployee.java

class file.

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import com.hp.empinfo.domain.EntityEmployee;

3.

Remove the following

import

statements that were used by Hibernate:

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

4.

Modify the following methods to use JPA

EntityManagerFactory

to perform database

operations:
a.

public Employee getDetail(int empid) throws SQLException

b.

public void insertDetail(int empid, String firstname, String

lastname, int age, String email) throws SQLException

c.

public String deleteEmployee(int empid)

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 javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import com.hp.empinfo.domain.EntityEmployee;
import com.hp.empinfo.domain.Employee;

406

Integrating JPA with Hibernate into Spring

This manual is related to the following products: