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

Page 251

Advertising
background image

1.

“Creating the persistence.xml File” (page 251)

2.

“Creating the EntityEmployee.java File” (page 251)

3.

“Modifying the applicationContext.xml File” (page 253)

4.

“Modifying the EmployeeDao.java File” (page 254)

5.

“Removing the Employee.hbm.xml File” (page 256)

6.

“Adding Dependency JAR Files” (page 256)

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 (JSTL)” (page 58)

section in the

“Getting Started

with Spring” (page 38)

section.

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” (page 48)

section in the

“Getting

Started with Spring” (page 38)

section.

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:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
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">

<persistence-unit name="Empinfo">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.hp.empinfo.domain.EntityEmployee</class>
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.SqlmxDialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.jdbc.batch_size" value="100" />
</properties>
</persistence-unit>
</persistence>

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” (page 54)

section in the

“Getting Started with Spring” (page 38)

section.

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;
import javax.persistence.Id;

Developing Spring JPA Applications Using Hibernate

251

Advertising
This manual is related to the following products: