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 Wynham-Price", "Ramsom House", "NON-FICTION" ) );
- int i = 1;
- for( Book b : books ) {
- EntityTransaction trans = em.getTransaction();
- trans.begin();
- em.persist( b );
- trans.commit();
- out.printf( "Record: %s%n", i++ );
- }
- String queryName = "Book.findAll";
- Query query = em.createNamedQuery( queryName );
- closeEntityManagerFactory();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement