Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javaoo.store.drivers;
- import static com.javaoo.store.JPAUtility.*;
- import static java.lang.System.*;
- import com.javaoo.store.*;
- import java.util.*;
- import javax.persistence.*;
- public class PopulateDatabase {
- public static void main(String[] args) {
- EntityManager em = getEntityManager();
- List<Book> books = new ArrayList<>();
- books.add( new Book( null, "Godzilla on Holiday", 24.95, 5, "Wesley Wyham-Price", "Ransom House", "FICTION" ) );
- books.add( new Book( null, "Loch Ness Memories", 49.95, 1, "Freddy McMurrey", "Penguin Press", "FICTION" ) );
- books.add( new Book( null, "MVS JCL", 89.95, 3, "Steve Balmer", "Microsoft Press", "NON-FICTION" ) );
- books.add( new Book( null, "Lingo in a Nutshell", 19.95, 8, "Bill Bates", "O'Reilly", "NON-FICTION" ) );
- int i = 1;
- for( Book b : books ) {
- EntityTransaction trans = em.getTransaction();
- trans.begin();
- em.persist( b );
- trans.commit();
- out.printf( "Book: %s%n", i++ );
- }
- List<CD> cds = new ArrayList<>();
- cds.add( new CD( null, "Going For The One", 12.95, 4, new Artist( null, "YES" ), new Date( "07/07/1977" ) ) );
- cds.add( new CD( null, "Blowing In The Wind", 15.95, 6, new Artist( null, "YES" ), new Date( "09/07/1968" ) ) );
- cds.add( new CD( null, "What Could Go Wrong", 11.87, 2, new Artist( null, "NO" ), new Date( "09/09/2018" ) ) );
- int j = 1;
- for( Book b : books ) {
- EntityTransaction trans = em.getTransaction();
- trans.begin();
- em.persist( b );
- trans.commit();
- out.printf( "CD: %s%n", j++ );
- }
- /*
- String queryName = "BookfindAll";
- Query query = em.createNamedQuery( queryName );
- */
- closeEntityManagerFactory();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement