List of usage examples for javax.persistence EntityManager close
public void close();
From source file:Address.java
License:asdf
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();/*ww w . jav a 2 s. c o m*/ service.addProfessor("12"); util.checkData("select * from EMP"); em.getTransaction().commit(); em.close(); emf.close(); }
From source file:Address.java
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();/*from www. j a va 2 s . c om*/ service.findProfessorsReportingTo(1); util.checkData("select * from EMP"); em.getTransaction().commit(); em.close(); emf.close(); }
From source file:Department.java
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();//from ww w . j a v a2 s . com service.findWithAlias(); util.checkData("select * from EMP"); em.getTransaction().commit(); em.close(); emf.close(); }
From source file:Department.java
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();/*from ww w . j a va 2 s. c o m*/ Collection<Professor> l = service.findAllProfessors(); util.checkData("select * from Professor"); util.checkData("select * from Department"); em.getTransaction().commit(); em.close(); emf.close(); }
From source file:Professor.java
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();/*w w w .jav a 2 s . c o m*/ long l = service.findSalaryForNameAndDepartment("deptName", "empName"); util.checkData("select * from Professor"); util.checkData("select * from Department"); em.getTransaction().commit(); em.close(); emf.close(); }
From source file:ContractProfessor.java
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();/*from w w w . java2 s. c om*/ Professor emp = null; emp = new ContractProfessor(); emp.setId(1); emp.setName("name"); service.createProfessor(emp); System.out.println("Professors: "); for (Professor emp1 : service.findAllProfessors()) { System.out.print(emp1); } util.checkData("select * from EMP"); em.getTransaction().commit(); em.close(); emf.close(); }
From source file:BadProfessor.java
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();/* www.jav a2 s . co m*/ BadProfessor emp2 = new BadProfessor(); emp2.setId(2); emp2.setName("bad"); service.createProfessor(emp2); System.out.println("Professors: "); for (Professor emp1 : service.findAllProfessors()) { System.out.print(emp1); } util.checkData("select * from EMP"); em.getTransaction().commit(); em.close(); emf.close(); }
From source file:Address.java
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();//from w w w. j a v a2 s . c om Professor emp = service.createProfessor("name", 100, "street", "city", "state", "zip"); em.getTransaction().commit(); System.out.println("Persisted " + emp); util.checkData("select * from Professor"); util.checkData("select * from ADDRESS"); util.checkData("select * from ID_GEN"); em.close(); emf.close(); }
From source file:Professor.java
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();/*from w w w. j av a 2s.co m*/ service.createProfessor("country", 1, "name"); System.out.println("Professors:"); for (Professor emp : service.findAllProfessors()) { System.out.print(emp); System.out.print(emp.getManager()); } util.checkData("select * from Professor"); em.getTransaction().commit(); em.close(); emf.close(); }
From source file:Address.java
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();/*ww w . j a v a2 s . c o m*/ Professor emp = service.createProfessor("name", 100, "street", "city", "state", "zip"); em.getTransaction().commit(); System.out.println("Persisted " + emp); util.checkData("select * from Professor"); util.checkData("select * from ADDRESS"); util.checkData("select * from ID_GEN"); em.close(); emf.close(); }