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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

MAPEAMENTO 423 EntityManagerFactory factory =4 Persistence . createEntityManagerFactory (" K21_mapeamento_pu ");5 EntityManager manager = factory . createEntityManager ();67 manager . getTransaction (). begin ();89 Pessoa p1 = new Pessoa ();10 p1. setNome (" Marcelo ");1112 PessoaFisica p2 = new PessoaFisica ();13 p2. setNome (" Rafael ");14 p2. setCpf (" 1234 ");1516 PessoaJuridica p3 = new PessoaJuridica ();17 p3. setNome (" K19 ");18 p3. setCnpj (" 567788 ");1920 manager . persist (p1);21 manager . persist (p2);22 manager . persist (p3);2324 manager . getTransaction (). <strong>com</strong>mit ();2526 manager . close ();27 factory . close ();28 }29 }Código Java 2.82: AdicionaPessoa.java33 Execute a classe AdicionaPessoa para adicionar algumas pessoas. Através do MySQL Workbench,verifique a tabela criada. Note que foi criada apenas a tabela Pessoa.42 www.k19.<strong>com</strong>.br

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

Saved successfully!

Ooh no, something went wrong!