package beans;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.persistence.TypedQuery;

import model.Employee;

@ManagedBean
public class HrBean {
	
	@PersistenceUnit(unitName="HR")
	private EntityManagerFactory emf;
	
	public List<Employee> getAllEmployees() {
		EntityManager em = null;
		try {
			em = emf.createEntityManager();
			
			TypedQuery<Employee> namedQuery = em.createNamedQuery("Employee.findAll", Employee.class);
			return namedQuery.getResultList();
		} finally {
			if(em != null)
				em.close();
		}
	}
}
