package beans;

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

import model.Employee;

@ManagedBean
@SessionScoped
public class Edytor {
	@PersistenceUnit(unitName="HR")
	private EntityManagerFactory emf;
	
	private long id;
	
	private Employee employee;
	
	public void init() {
		System.out.println("init");
		EntityManager em = null;
		try {
			em = emf.createEntityManager();
			employee = em.find(Employee.class, id);
			System.out.println("Jest pracownik " + em + " " + id);
			
		} finally {
			if(em != null)
				em.close();
		}		
	}

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}
	
	

}
