Set<AddressOracleNoSqlOTM> addresses = new HashSet<AddressOracleNoSqlOTM>();
addresses.add(address1);
addresses.add(address2);
PersonOracleNoSqlOTM person = new PersonOracleNoSqlOTM();
person.setPersonId("1");
person.setPersonName("Kuldeep");
person.setAddresses(addresses);
em.persist(person);
em = getNewEM();
PersonOracleNoSqlOTM foundPerson = em.find(PersonOracleNoSqlOTM.class, "1");
Assert.assertNotNull(foundPerson);
Assert.assertNotNull(foundPerson.getAddresses());
Assert.assertEquals("1", foundPerson.getPersonId());
Assert.assertEquals("Kuldeep", foundPerson.getPersonName());
int counter = 0;
for (AddressOracleNoSqlOTM 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);
foundPerson.setPersonName("KK");
em.merge(foundPerson);
em = getNewEM();
foundPerson = em.find(PersonOracleNoSqlOTM.class, "1");
Assert.assertNotNull(foundPerson);
Assert.assertNotNull(foundPerson.getAddresses());
Assert.assertEquals("1", foundPerson.getPersonId());
Assert.assertEquals("KK", foundPerson.getPersonName());
counter = 0;
for (AddressOracleNoSqlOTM address : foundPerson.getAddresses()) {
if (address.getAddressId().equals("a")) {
counter++;
Assert.assertEquals("sector 11", address.getStreet());
} else {
Assert.assertEquals("b", address.getAddressId());