@@ -10,26 +10,48 @@ public class PersistenceTester {
10
10
11
11
public static void main (String [] args ) {
12
12
EntityManagerFactory emf = Persistence .createEntityManagerFactory ("anirtek-jpa" );
13
-
13
+
14
14
EntityManager em = emf .createEntityManager ();
15
-
16
- // INSERT INTO action
17
- // Employee emp = new Employee();
18
- // emp.setFirstName("Mayank");
19
- // emp.setLastName("Jain");
20
- // emp.setEmail("mjain8@binghamton.edu");
21
- // emp.setCity("San Francisco");
22
- //
23
- // em.getTransaction().begin();
24
- // em.persist(emp);
25
- // em.getTransaction().commit();
26
-
27
- // FIND BY ID
28
- Employee emp = em .find (Employee .class , "a13f3cb4-0530-4e2e-b7c0-dbfc75953426" );
29
- System .out .println (emp .toString ());
30
-
15
+
16
+ // INSERT INTO action
17
+ // Employee emp = new Employee();
18
+ // emp.setFirstName("Mayank");
19
+ // emp.setLastName("Jain");
20
+ // emp.setEmail("mjain8@binghamton.edu");
21
+ // emp.setCity("San Francisco");
22
+ //
23
+ // em.getTransaction().begin();
24
+ // em.persist(emp);
25
+ // em.getTransaction().commit();
26
+
27
+ // FIND BY ID
28
+ // Employee emp = em.find(Employee.class,
29
+ // "a13f3cb4-0530-4e2e-b7c0-dbfc75953426");
30
+ // Employee emp = em.find(Employee.class, "a13f3cb4dbfc75953426");
31
+ // System.out.println(emp.toString());
32
+
33
+ // UPDATE BY ID
34
+ // Employee emp = em.find(Employee.class,
35
+ // "a13f3cb4-0530-4e2e-b7c0-dbfc75953426");
36
+ // emp.setFirstName("Jack");
37
+ // emp.setLastName("Sparrow");
38
+ // emp.setEmail("jsparrow@binghamton.edu");
39
+ // emp.setCity("Los Angeles");
40
+ //
41
+ // em.getTransaction().begin();
42
+ // em.merge(emp);
43
+ // em.getTransaction().commit();
44
+
45
+ // DELETE
46
+ // Employee emp = em.find(Employee.class,
47
+ // "a13f3cb4-0530-4e2e-b7c0-dbfc75953426");
48
+ // if (emp != null) {
49
+ // em.getTransaction().begin();
50
+ // em.remove(emp);
51
+ // em.getTransaction().commit();
52
+ // }
53
+
31
54
em .close ();
32
-
33
- // emf.close();
55
+ emf .close ();
34
56
}
35
57
}
0 commit comments