* the exception
*/
@Test
public void onInsertUsers() throws Exception
{
Users u = new Users();
u.setFirstName("firstname");
u.setLastName("lastname");
u.setUserId("1_u");
PromoCode promoCode1 = new PromoCode();
promoCode1.setPromoCodeId("1_p");
promoCode1.setPromoCodeName("promoname1");
u.getPromoCodes().add(promoCode1);
em.persist(u);
em.clear(); // to avoid fetch from cache and get from DB.
Users found = em.find(Users.class, "1_u");
Assert.assertNotNull(found);
Assert.assertEquals("firstname", found.getFirstName());
Assert.assertEquals(1, found.getPromoCodes().size());
// add 1 more promo code.
PromoCode promoCode = new PromoCode();
promoCode.setPromoCodeId("2_p");
promoCode.setPromoCodeName("promoname2");
found.getPromoCodes().add(promoCode);
em.merge(found);
em.clear(); // to avoid fetch from cache get from DB.
found = em.find(Users.class, "1_u");
Assert.assertNotNull(found);
Assert.assertEquals("firstname", found.getFirstName());
Assert.assertEquals(2, found.getPromoCodes().size());
// Delete
em.remove(found);
found = em.find(Users.class, "1_u");