@Test public void shouldShowDifferentLifeCyclePhases() throws Exception { Customer customer = new Customer("John", "Smith", "jsmith@gmail.com", "1234565"); assertFalse(em.contains(customer)); System.out.println("\nPERSIST"); tx.begin(); em.persist(customer); tx.commit(); assertTrue(em.contains(customer), "should be in the persistence context after persisting"); System.out.println("\nFIND"); em.clear(); assertFalse(em.contains(customer), "should not be in the persistence context after clearing"); customer = em.find(Customer.class, customer.getId()); assertTrue(em.contains(customer), "should be in the persistence context after finding"); System.out.println("\nDETACH"); em.detach(customer); assertFalse(em.contains(customer), "should not be in the persistence context after detaching"); customer = em.find(Customer.class, customer.getId()); assertTrue(em.contains(customer), "should be in the persistence context after finding"); System.out.println("\nREFRESH"); customer.setEmail("newone@mail.com"); tx.begin(); em.refresh(customer); tx.commit(); assertTrue(em.contains(customer), "should be in the persistence context after refreshing"); System.out.println("\nSET"); tx.begin(); customer.setFirstName("new first name"); customer.setFirstName("new last name"); tx.commit(); System.out.println("\nMERGE"); em.clear(); assertFalse(em.contains(customer), "should not be in the persistence context after clearing"); customer.setEmail("newone@mail.com"); tx.begin(); customer = em.merge(customer); tx.commit(); assertTrue(em.contains(customer), "should be in the persistence context after merging"); System.out.println("\nREMOVE"); tx.begin(); em.remove(customer); tx.commit(); assertFalse(em.contains(customer), "should not be in the persistence context after removing"); }
public void setEmail(String email) { this.email = email; }
Customer extends Person { public void setEmail(String email) { this.email = email; } }
Customer extends Person { public void setEmail(String email) { this.email = email; } Customer();  Customer(String firstName, String lastName, String email, String phoneNumber); }
Customer extends Person { public void setEmail(String email) { this.email = email; } Customer();  Customer(String firstName, String lastName, String email, String phoneNumber); String getEmail(); void setEmail(String email); String getPhoneNumber(); void setPhoneNumber(String phoneNumber); Integer getAge(); void setAge(Integer age); }
Customer extends Person { public void setEmail(String email) { this.email = email; } Customer();  Customer(String firstName, String lastName, String email, String phoneNumber); String getEmail(); void setEmail(String email); String getPhoneNumber(); void setPhoneNumber(String phoneNumber); Integer getAge(); void setAge(Integer age);  }