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.

99 JPQL26 Testes as consultas nativas. Acrescente a seguinte classe no pacote br.<strong>com</strong>.k19.testes do projetoK19-JPQL.1 public class TesteConsultaNativas {2 public static void main ( String [] args ) {3 EntityManagerFactory factory = Persistence . createEntityManagerFactory (" K21_jpql_pu←");45 EntityManager manager = factory . createEntityManager ();67 String sql = " SELECT * FROM Produto ";8 Query nativeQuery = manager . createNativeQuery (sql , Produto . class );9 List < Produto > produtos = nativeQuery . getResultList ();1011 for ( Produto p : produtos ) {12 System . out . println (p. getNome ());13 }14 }15 }Código Java 4.93: TesteConsultaNativas.javawww.k19.<strong>com</strong>.br 99

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

Saved successfully!

Ooh no, something went wrong!