Skip to content

Instantly share code, notes, and snippets.

@thjanssen
Created September 22, 2015 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thjanssen/f689a04d99cc36f0d578 to your computer and use it in GitHub Desktop.
Save thjanssen/f689a04d99cc36f0d578 to your computer and use it in GitHub Desktop.
// call the named query
Query nq = this.em.createNamedQuery("selectAuthorOfBook2");
List<AuthorValue> authors = nq.getResultList();
// call the named query
TypedQuery<Author> nq = this.em.createNamedQuery("selectAuthorOfBook", Author.class);
nq.setParameter("title", "%Java%");
List<Author> authors = nq.getResultList();
// 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);
// 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