Skip to content

Commit 9d3683d

Browse files
author
anirtek
committed
query UPDATE and DELETE BY ID
1 parent 0a94619 commit 9d3683d

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

src/main/java/io/anirtek/persistence/PersistenceTester.java

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,48 @@ public class PersistenceTester {
1010

1111
public static void main(String[] args) {
1212
EntityManagerFactory emf = Persistence.createEntityManagerFactory("anirtek-jpa");
13-
13+
1414
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+
3154
em.close();
32-
33-
// emf.close();
55+
emf.close();
3456
}
3557
}
Binary file not shown.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy