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.

HIBERNATE SEARCH 1264 xsi:schemaLocation =" http: // java . sun . <strong>com</strong> / xml /ns/ persistence http: // java . sun . <strong>com</strong> / xml /←ns/ persistence / persistence_2_0 . xsd ">56 7 org . hibernate . ejb . <strong>Hibernate</strong>Persistence 8 9 11 12 13 15 16 17 19 21 23 24 25 Código XML A.2: persistence.xml6 Crie um pacote chamado modelo no projeto K19-<strong>Hibernate</strong>-Search e adicione a seguinteclasse:1 @Entity2 @Indexed3 public class Pessoa {45 @Id @GeneratedValue6 private Long id;78 @Field9 private String nome ;1011 // GETTERS E SETTERS12 }Código Java A.7: Pessoa.java7 Persista alguns objeto da classe Pessoa. Crie uma classe chamada AdicionaPessoa dentro deum pacote chamado testes.1 public class AdicionaPessoa {2 public static void main ( String [] args ) {3 EntityManagerFactory factory =4 Persistence . createEntityManagerFactory (" K21_hibernate_search ");5 EntityManager manager = factory . createEntityManager ();67 manager . getTransaction (). begin ();89 Pessoa p1 = new Pessoa ();10 p1. setNome (" Rafael Cosentino ");1112 Pessoa p2 = new Pessoa ();13 p2. setNome (" Jonas Hirata ");1415 Pessoa p3 = new Pessoa ();16 p3. setNome (" Marcelo Martins ");1718 Pessoa p4 = new Pessoa ();19 p4. setNome (" Christopher Hirata ");126 www.k19.<strong>com</strong>.br

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

Saved successfully!

Ooh no, something went wrong!