Set<AddressRDBMSOTM> addresses = new HashSet<AddressRDBMSOTM>();
addresses.add(address1);
addresses.add(address2);
PersonLazyRDBMSOTM person = new PersonLazyRDBMSOTM();
person.setPersonId("1");
person.setPersonName("Kuldeep");
person.setAddresses(addresses);
em.persist(person);
em = getNewEM();
PersonLazyRDBMSOTM foundPerson = em.find(PersonLazyRDBMSOTM.class, "1");
Assert.assertNotNull(foundPerson);
Assert.assertNotNull(foundPerson.getAddresses());
Assert.assertEquals("1", foundPerson.getPersonId());
Assert.assertEquals("Kuldeep", foundPerson.getPersonName());
int counter = 0;
for (AddressRDBMSOTM address : foundPerson.getAddresses())
{
if (address.getAddressId().equals("a"))
{
counter++;
Assert.assertEquals("sector 11", address.getStreet());
}
else
{
Assert.assertEquals("b", address.getAddressId());
Assert.assertEquals("sector 12", address.getStreet());
counter++;
}
}
Assert.assertEquals(2, counter);
List<PersonLazyRDBMSOTM> persons = em.createQuery("Select p from PersonLazyRDBMSOTM p").getResultList();
Assert.assertNotNull(persons);
Assert.assertFalse(persons.isEmpty());
foundPerson.setPersonName("KK");
em.merge(foundPerson);
em = getNewEM();
foundPerson = em.find(PersonLazyRDBMSOTM.class, "1");
Assert.assertNotNull(foundPerson);
Assert.assertNotNull(foundPerson.getAddresses());
Assert.assertEquals("1", foundPerson.getPersonId());
Assert.assertEquals("KK", foundPerson.getPersonName());
counter = 0;
for (AddressRDBMSOTM address : foundPerson.getAddresses())
{
if (address.getAddressId().equals("a"))
{
counter++;
Assert.assertEquals("sector 11", address.getStreet());