Removing the employee.hbm.xml file – HP Integrity NonStop H-Series User Manual
Page 407

public class EmployeeDao {
private EntityManagerFactory entityManagerFactory;
public void setEntityManagerFactory(
EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory;
}
public Employee getDetail(int empid) throws SQLException {
EntityManager em = entityManagerFactory.createEntityManager();
EntityTransaction t = em.getTransaction();
t.begin();
List
"from EntityEmployee where emp_id=" + empid).getResultList();
Iterator
EntityEmployee entityEmployee = i.next();
Employee employee = new Employee();
employee.setEmpid(entityEmployee.getEmp_id());
employee.setFirstname(entityEmployee.getFirst_name());
employee.setLastname(entityEmployee.getLast_name());
employee.setAge(entityEmployee.getAge());
employee.setEmail(entityEmployee.getEmail());
em.flush();
t.commit();
return employee;
}
public void insertDetail(int empid, String firstname, String lastname,
int age, String email) throws SQLException {
EntityManager em = entityManagerFactory.createEntityManager();
EntityTransaction t = em.getTransaction();
t.begin();
EntityEmployee entityEmployee = new EntityEmployee(empid, firstname,
lastname, age, email);
em.persist(entityEmployee);
em.flush();
t.commit();
}
public String deleteEmployee(int empid) {
EntityManager em = entityManagerFactory.createEntityManager();
EntityTransaction t = em.getTransaction();
t.begin();
EntityEmployee entityEmployee = em.find(EntityEmployee.class,
new Integer(empid));
em.remove(entityEmployee);
em.flush();
t.commit();
return "Employee deleted";
}
}
Removing the
Employee.hbm.xml
File
JPA annotations (
EntityEmployee.java
class) have been used to map the database entities.
Hence, the Hibernate Mapping file (
Employee.hbm.xml)
is no longer needed and is removed.
Example of Integrating JPA with Hibernate into Spring
407