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

Page 389

Advertising
background image

<property name="username">
<value>${jdbc.user}</value>
</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="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="Empinfo" />
</bean>

<bean id="empdao" class="com.hp.empinfo.service.EmployeeDao">
<property name="entityManagerFactory">
<ref bean="entityManagerFactory" />
</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, 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:

Example of Integrating JPA with Hibernate into Spring 389

Advertising
This manual is related to the following products: