11.07.2015 Views

Persistência com JPA2 e Hibernate - Inpi

Persistência com JPA2 e Hibernate - Inpi

Persistência com JPA2 e Hibernate - Inpi

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

RESPOSTASA P Ê N D I C EEResposta do Complementar 1.11 @Entity2 public class Autor {34 @Id @GeneratedValue5 private Long id;67 private String nome ;89 // GETTERS E SETTERS10 }Código Java 1.4: Autor.javaResposta do Complementar 1.21 public class GeraTabelas {2 public static void main ( String [] args ) {3 EntityManagerFactory factory =4 Persistence . createEntityManagerFactory (" K21_livraria ");56 factory . close ();7 }8 }Código Java 1.5: GeraTabelas.javaResposta do Complementar 1.31 public class InsereAutorComJPA {23 public static void main ( String [] args ) {4 EntityManagerFactory factory =5 Persistence . createEntityManagerFactory (" K21_livraria_pu ");67 EntityManager manager = factory . createEntityManager ();89 Autor novoAutor = new Autor ();1011 Scanner entrada = new Scanner ( System .in);1213 System . out . println (" Digite o nome do autor : ");14 novoAutor . setNome ( entrada . nextLine ());1516 manager . persist ( novoAutor );17www.k19.<strong>com</strong>.br 183

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!