Creating the main class – HP Integrity NonStop H-Series User Manual
Page 339

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 the
section.
2.
Create
Test.java main
class file in the
com.hp.imp
package, as explained in the
section.
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();
System.out.println("Employee found using HQL" + "\n"
Overview of EmpIoyeeInfo
339