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

Page 206

Advertising
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 follows:

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

To create a Main class, complete the following steps:
1.

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

“Creating the Package for the

EmployeeInfo Application” (page 204)

.

2.

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

“Creating

the Employee.java Class File” (page 204)

.

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

206 Getting Started with Hibernate

Advertising
This manual is related to the following products: