-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJPAText.java
More file actions
45 lines (33 loc) · 1.15 KB
/
JPAText.java
File metadata and controls
45 lines (33 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class JPATest {
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("rpsdb");
EntityManager em = emf.createEntityManager();
try {
em.getTransaction().begin();
Score score = em.find(Score.class, new Long(1));
System.out.println(score);
System.out.println("***");
score.wins = Integer.parseInt(score.wins)+1 + "";
List<GameSummary> l = em.createQuery("Select gs from GameSummary gs").getResultList();
//List<GameSummary> l = em.createQuery("select gs from GameSummary gs WHERE gs.result='TIE'").getResultList();
System.out.println(l.size());
for (GameSummary cur : l) {
System.out.println(cur);
}
GameSummary gs = new GameSummary();
gs.client = "Rock";
gs.server = "Paper";
gs.result = "Loss";
gs.date = new java.util.Date();
gs.id = 0;
em.persist(gs);;
em.getTransaction().commit();
}
catch (Exception ex) { ex.printStackTrace(); }
finally { em.close(); }
}
}