Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. package com.javaoo.store.drivers;
  2.  
  3. import static com.javaoo.store.JPAUtility.*;
  4. import static java.lang.System.*;
  5. import com.javaoo.store.*;
  6. import java.util.*;
  7. import javax.persistence.*;
  8.  
  9. public class PopulateDatabase {
  10.  
  11. public static void main(String[] args) {
  12. EntityManager em = getEntityManager();
  13.  
  14. List<Book> books = new ArrayList<>();
  15. books.add( new Book( null, "Godzilla on Holiday", 24.95, 5, "Wesley Wynham-Price", "Ramsom House", "NON-FICTION" ) );
  16.  
  17. int i = 1;
  18. for( Book b : books ) {
  19. EntityTransaction trans = em.getTransaction();
  20. trans.begin();
  21. em.persist( b );
  22. trans.commit();
  23. out.printf( "Record: %s%n", i++ );
  24. }
  25.  
  26. String queryName = "Book.findAll";
  27. Query query = em.createNamedQuery( queryName );
  28.  
  29. closeEntityManagerFactory();
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement