Guest User

Untitled

a guest
Jun 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. @Entity
  2. public class Foo {
  3.  
  4. @Id
  5. private Long id;
  6.  
  7. private String name;
  8.  
  9. // <init>s and getters and setters
  10.  
  11.  
  12. public class EntityTests
  13.  
  14. private String name;
  15. @Test
  16. public void test2() throws Exception {
  17. EntityManager entityManager = entityManagerFactory.createEntityManager();
  18. entityManager.getTransaction().begin();
  19.  
  20. Foo foo=new Foo(1l,"bar");
  21. entityManager.persist(foo);
  22.  
  23. entityManager.getTransaction().commit();
  24. entityManager.close();
  25.  
  26. entityManager = entityManagerFactory.createEntityManager();
  27. entityManager.getTransaction().begin();
  28.  
  29. Foo foo2=new Foo(1l,"baz");
  30. entityManager.persist(foo2);
  31.  
  32. entityManager.getTransaction().commit();
  33. entityManager.close();
  34. }
  35.  
  36. sql> select*from foo;
  37. ID | NAME
  38. 1 | bar
  39. 1 | baz
Add Comment
Please, Sign In to add comment