beautypg.com

Creating the persistence.xml file, Creating the entityemployee.java file – HP Integrity NonStop H-Series User Manual

Page 403

background image

Modifying the EmpInfo application involves the following activities:

1.

Creating the persistence.xml File

2.

Creating the EntityEmployee.java File

3.

Modifying the

applicationContext.xml

File

4.

Modifying the

EmployeeDao.java

File

5.

Removing the Employee.hbm.xml File

6.

Adding Dependency

JAR

Files

Creating the

persistence.xml

File

Create the

persistence.xml

file to define a persistence unit called Empinfo to define a set of

classes and their mapping characteristics.

To create

persistence.xml

, complete the following steps:

1.

Create a folder named META-INF in the

EmpInfo/src

directory, as explained in the

Configuring the JSP Standard Tag Library

section in the

Getting Started with Spring

chapter.

2.

Create a new XML file

persistence.xml

in the

EmpInfo/src

/

META-INF

directory, as

explained in the

Creating the

EmpInfo-servlet.xml

File

section in the

Getting Started

with Spring

chapter.

3.

Modify the

persistence.xml

file to provide the persistence unit named Empinfo and

Hibernate-related configuration.

After modification, the

persistence.xml

file appears as:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">


org.hibernate.ejb.HibernatePersistence
com.hp.empinfo.domain.EntityEmployee

value="org.hibernate.dialect.SqlmxDialect" />





Creating the

EntityEmployee.java

File

EntityEmployee.java

is a JPA Persistence class. This class is used to map the database entities

using JPA annotations such as @Entity, @Id, and @Basic.

To create the

EntityEmployee.java

class under the

com.hp.empinfo.domain

package,

complete the following steps:

1.

Create the Java class

EntityEmployee.java

, as explained in the

Creating the Controller

for EmpInfo

section in the

Getting Started with Spring

chapter.

2.

Modify the

EntityEmployee.java

class to add the application properties and their getter

and setter methods to map with the Employee database table.

After modification, the

EntityEmployee.java

appears as:

package com.hp.empinfo.domain;

import javax.persistence.Basic;
import javax.persistence.Entity;

Example of Integrating JPA with Hibernate into Spring

403

This manual is related to the following products: