Skip to content

Instantly share code, notes, and snippets.

@thjanssen
Last active June 24, 2016 02:10
Show Gist options
  • Save thjanssen/af62a32c29b6820a66adfbdef06549f5 to your computer and use it in GitHub Desktop.
Save thjanssen/af62a32c29b6820a66adfbdef06549f5 to your computer and use it in GitHub Desktop.
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
Author a = em.createQuery("SELECT a FROM Author a JOIN FETCH a.books WHERE a.id = 1", Author.class).getSingleResult();
em.getTransaction().commit();
em.close();
log.info(a.getFirstName()+" "+a.getLastName()+" wrote "+a.getBooks().size()+" books.");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
Author a = em.createQuery("SELECT a FROM Author a WHERE id = 1", Author.class).getSingleResult();
em.getTransaction().commit();
em.close();
log.info(a.getFirstName()+" "+a.getLastName()+" wrote "+a.getBooks().size()+" books.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment