Modifying the applicationcontext.xml file, Modifying the, Applicationcontext.xml – HP Integrity NonStop H-Series User Manual

Page 405: File

Advertising
background image

this.email = email;
}

}

Modifying the

applicationContext.xml

File

Modify the

EmpInfo/WebContent/WEB-INF/applicationContext.xml

file, so that it uses

JPA

EntityManagerFactory

to connect to the employee SQL/MX database table, in place of

Hibernate SessionFactory.

To modify the

applicationContext.xml

file, complete the following steps:

1.

Specify the

EntityManagerFactory

in the

applicationContext.xml

file as shown:

<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="Empinfo" />
</bean>

2.

Remove the

<bean>

tag with the

sessionFactory

ID from the

applicationContext.xml

file.

<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>

3.

Replace the reference of Hibernate

sessionFactory

with the JPA

entityManagerFactory

in the bean instance of the

EmployeeDao

class, as shown:

<bean id="empdao" class="com.hp.springapp.service.EmployeeDao">
<property name="entityManagerFactory">
<ref bean="entityManagerFactory" />
</property>
</bean>

After modification, the

applicationContext.xml

file should appear as:

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
destroy-method="close">
<property name="driverClassName">
<value>${jdbc.driver}</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<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">

Example of Integrating JPA with Hibernate into Spring

405

Advertising
This manual is related to the following products: