SHARE
TWEET

Untitled

a guest Jun 25th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top