Set<AddressOracleNoSqlMTM> addresses2 = new HashSet<AddressOracleNoSqlMTM>();
addresses2.add(address2);
addresses2.add(address3);
PersonOracleNoSqlMTM person1 = new PersonOracleNoSqlMTM();
person1.setPersonId("1");
person1.setPersonName("Kuldeep");
PersonOracleNoSqlMTM person2 = new PersonOracleNoSqlMTM();
person2.setPersonId("2");
person2.setPersonName("vivek");
person1.setAddresses(addresses1);
person2.setAddresses(addresses2);
em.persist(person1);
em.persist(person2);
em = getNewEM();
PersonOracleNoSqlMTM foundPerson1 = em.find(PersonOracleNoSqlMTM.class, "1");
Assert.assertNotNull(foundPerson1);
Assert.assertNotNull(foundPerson1.getAddresses());
Assert.assertEquals("1", foundPerson1.getPersonId());
Assert.assertEquals("Kuldeep", foundPerson1.getPersonName());
int counter = 0;
for (AddressOracleNoSqlMTM address : foundPerson1.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++;
}
}
PersonOracleNoSqlMTM foundPerson2 = em.find(PersonOracleNoSqlMTM.class, "2");
Assert.assertNotNull(foundPerson2);
Assert.assertNotNull(foundPerson2.getAddresses());
Assert.assertEquals("2", foundPerson2.getPersonId());
Assert.assertEquals("vivek", foundPerson2.getPersonName());
counter = 0;
for (AddressOracleNoSqlMTM address : foundPerson2.getAddresses()) {
if (address.getAddressId().equals("b")) {
counter++;
Assert.assertEquals("sector 12", address.getStreet());
} else {
Assert.assertEquals("c", address.getAddressId());
Assert.assertEquals("sector 13", address.getStreet());
counter++;
}
}
foundPerson1.setPersonName("KK");
foundPerson2.setPersonName("vives");
em.merge(foundPerson1);
em.merge(foundPerson2);
em = getNewEM();
foundPerson1 = em.find(PersonOracleNoSqlMTM.class, "1");
Assert.assertNotNull(foundPerson1);
Assert.assertNotNull(foundPerson1.getAddresses());
Assert.assertEquals("1", foundPerson1.getPersonId());
Assert.assertEquals("KK", foundPerson1.getPersonName());
counter = 0;
for (AddressOracleNoSqlMTM address : foundPerson1.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++;
}
}
foundPerson2 = em.find(PersonOracleNoSqlMTM.class, "2");
Assert.assertNotNull(foundPerson2);
Assert.assertNotNull(foundPerson2.getAddresses());
Assert.assertEquals("2", foundPerson2.getPersonId());
Assert.assertEquals("vives", foundPerson2.getPersonName());
counter = 0;
for (AddressOracleNoSqlMTM address : foundPerson2.getAddresses()) {
if (address.getAddressId().equals("b")) {
counter++;
Assert.assertEquals("sector 12", address.getStreet());
} else {
Assert.assertEquals("c", address.getAddressId());