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.

181 MAPEAMENTO COM XML39 Crie um teste para adicionar pessoas. No pacote br.<strong>com</strong>.k19.testes do projeto K19-Mapeamento-XML adicione a seguinte classe:1 public class AdicionaPessoa {2 public static void main ( String [] args ) {3 EntityManagerFactory factory = Persistence . createEntityManagerFactory ("←K21_mapeamento_xml_pu ");4 EntityManager manager = factory . createEntityManager ();56 manager . getTransaction (). begin ();78 Pessoa p1 = new Pessoa ();9 p1. setNome (" Marcelo ");1011 PessoaFisica p2 = new PessoaFisica ();12 p2. setNome (" Rafael ");13 p2. setCpf (" 1234 ");1415 PessoaJuridica p3 = new PessoaJuridica ();16 p3. setNome (" K19 ");17 p3. setCnpj (" 567788 ");1819 manager . persist (p1);20 manager . persist (p2);21 manager . persist (p3);2223 manager . getTransaction (). <strong>com</strong>mit ();2425 manager . close ();26 factory . close ();27 }28 }Código Java D.64: AdicionaPessoa.javawww.k19.<strong>com</strong>.br 181

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

Saved successfully!

Ooh no, something went wrong!