Posted by Anonymous on Wed 7th Feb 17:03
download | new post
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("gello");
- EntityManager em = emf.createEntityManager();
- EntityTransaction et = em.getTransaction();
- et.begin();
- User user = (User) em.createNamedQuery("User.findByUserName").setParameter("username", "dan").getSingleResult();
- EmailAddress ea1 = new EmailAddress();
- ea1.setUser(user);
- ea1.setEmailAddressType(EmailAddressType.FIRST);
- user.getEmailAddresses().add(ea1);
- et.commit();
- //detached
- user.getEmailAddresses().clear();
- EmailAddress ea2 = new EmailAddress();
- ea2.setUser(user);
- ea2.setEmailAddressType(EmailAddressType.SECOND);
- user.getEmailAddresses().add(ea2);
- et = em.getTransaction();
- et.begin();
- em.merge(user);
- printEmails(user);
- et.commit();
- em.close();
- emf.close();
Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.