beautypg.com

Creating the main class – HP Integrity NonStop J-Series User Manual

Page 131

background image

3.

Modify the Employee.java class file to add the application attributes and their getter and
setter methods, so that it appears as:

package com.hp.domain;

public class Employee {
private int id;
private String fname;
private String lname;
private int age;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}

Creating the Main Class

1.

Create the com.hp.imp Java package, as explained in

“Creating the Package for the

EmployeeInfo Application” (page 129)

.

2.

Create Test.java main class file in the com.hp.imp package, as explained in

“Creating

the Employee.java Class File” (page 129)

.

3.

Replace the contents of the Test.java file with the following code to implement the
functionality for the Hibernate session factory and the Main method:

package com.hp.imp;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.hp.domain.Employee;

public class Test {

public Session openSession() {
SessionFactory sessionFactory;
Configuration cfg = new Configuration().configure();
sessionFactory = cfg.buildSessionFactory();
Session session = sessionFactory.openSession();
return session;
}

public void testFindByHQL(TestManager manager) {
Employee emp = manager.getEmpl();

Getting Started with Hibernate

131

This manual is related to the following products: