@Test public void testRead() { List<Company> cp = em.createNamedQuery("Company.findByAll", Company.class).getResultList(); assertTrue(cp.size() == 1); assertFalse(cp.isEmpty()); for (Company r : cp) { System.out.println(r.toString()); for (Products p : r.getProducts()) { System.out.println("\t" + p.toString()); } } }
@Test @Ignore public void testDelete() { TypedQuery<Company> cb = em.createQuery("select cb from Company cb where cb.name = ?1", Company.class); cb.setParameter(1, "Pepsico"); Company c = cb.getSingleResult(); assertNotNull(c.getId()); tx.begin(); for (Products d : c.getProducts()) { em.remove(d); } em.remove(c); tx.commit(); Company postRemove = em.find(Company.class, 1L); assertNull(postRemove); }