Created
September 22, 2015 18:00
-
-
Save thjanssen/f689a04d99cc36f0d578 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// call the named query | |
Query nq = this.em.createNamedQuery("selectAuthorOfBook2"); | |
List<AuthorValue> authors = nq.getResultList(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// call the named query | |
TypedQuery<Author> nq = this.em.createNamedQuery("selectAuthorOfBook", Author.class); | |
nq.setParameter("title", "%Java%"); | |
List<Author> authors = nq.getResultList(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// define the named query | |
Query q = this.em.createNativeQuery("SELECT a.id, a.firstName, a.lastName FROM Author a", "AuthorValue"); | |
q.setFirstResult(0); | |
q.setMaxResults(5); | |
this.em.getEntityManagerFactory().addNamedQuery("selectAuthorOfBook2", q); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// define the named query | |
Query q = this.em.createQuery("SELECT a FROM Book b JOIN b.authors a WHERE b.title LIKE :title GROUP BY a"); | |
this.em.getEntityManagerFactory().addNamedQuery("selectAuthorOfBook", q); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment