em = emf.createEntityManager();
begin();
print("Checking " + NUMBER_OF_INSTANCES + " instances.");
for (int i = 0; i < NUMBER_OF_INSTANCES; ++i) {
b = em.find(LongIntStringFKOneOne.class, new LongIntStringOid(OFFSET_B + i));
a = em.find(LongIntStringPKOneOne.class, new LongIntStringOid(OFFSET_A + i));
errorIfNull("Instance of LongIntStringPKOneOne for value " + (OFFSET_A + i) + " was not found.", a);
errorIfNull("Instance of LongIntStringFKOneOne for value " + (OFFSET_B + i) + " was not found.", b);
if (b != null && a != null) {
errorIfNotEqual("Mismatch in longIntStringFKOneOne.getLongIntStringPKOneOne",
a, b.getLongIntStringPKOneOne());
errorIfNotEqual("Mismatch in longIntStringPKOneOne.getLongIntStringFKOneOne",
b, a.getLongIntStringFKOneOne());
}
}
commit();
em.close();
em = emf.createEntityManager();
print("Deleting some instances.");
begin();
// delete a0; set b0.a = null
a = em.find(LongIntStringPKOneOne.class, new LongIntStringOid(OFFSET_A + 0));
b = em.find(LongIntStringFKOneOne.class, new LongIntStringOid(OFFSET_B + 0));
b.setLongIntStringPKOneOne(null);
em.remove(a);
a = em.find(LongIntStringPKOneOne.class, new LongIntStringOid(OFFSET_A + 1));
b = em.find(LongIntStringFKOneOne.class, new LongIntStringOid(OFFSET_B + 1));
a.setLongIntStringFKOneOne(null);
em.remove(b);
commit();
em.close();
em = emf.createEntityManager();
begin();
print("Checking deleted instances.");
a = em.find(LongIntStringPKOneOne.class, new LongIntStringOid(OFFSET_A + 0));
errorIfNotEqual("finding deleted instance of LongIntStringPK should return null", null, a);
b = em.find(LongIntStringFKOneOne.class, new LongIntStringOid(OFFSET_B + 1));
errorIfNotEqual("finding deleted instance of LongIntStringFK should return null", null, b);
a = em.find(LongIntStringPKOneOne.class, new LongIntStringOid(OFFSET_A + 1));
b = em.find(LongIntStringFKOneOne.class, new LongIntStringOid(OFFSET_B + 0));
errorIfNull("Instance of LongIntStringPKOneOne for value " + (OFFSET_A + 1) + " was not found.", a);
errorIfNull("Instance of LongIntStringFKOneOne for value " + (OFFSET_B + 0) + " was not found.", b);
if (b != null && a != null) {
errorIfNotEqual("field longIntStringFKOneOne should be null",
null, a.getLongIntStringFKOneOne());
errorIfNotEqual("field longIntStringPKOneOne should be null",
null, b.getLongIntStringPKOneOne());
}
commit();
em.close();
em = emf.createEntityManager();
begin();
print("Setting fields to null");
a = em.find(LongIntStringPKOneOne.class, new LongIntStringOid(OFFSET_A + 2));
b = em.find(LongIntStringFKOneOne.class, new LongIntStringOid(OFFSET_B + 2));
b.setLongIntStringPKOneOne(null);
a.setLongIntStringFKOneOne(null);
commit();
em.close();
em = emf.createEntityManager();
begin();
print("Checking fields set to null.");
a = em.find(LongIntStringPKOneOne.class, new LongIntStringOid(OFFSET_A + 2));
b = em.find(LongIntStringFKOneOne.class, new LongIntStringOid(OFFSET_B + 2));
if (b != null && a != null) {
errorIfNotEqual("field longIntStringFKOneOne should be null",
null, a.getLongIntStringFKOneOne());
errorIfNotEqual("field longIntStringPKOneOne should be null",
null, b.getLongIntStringPKOneOne());
}
commit();
em.close();
em = emf.createEntityManager();
begin();
print("Swapping references.");
LongIntStringPKOneOne a3 = em.find(LongIntStringPKOneOne.class, new LongIntStringOid(OFFSET_A + 3));
LongIntStringPKOneOne a4 = em.find(LongIntStringPKOneOne.class, new LongIntStringOid(OFFSET_A + 4));
LongIntStringFKOneOne b3 = em.find(LongIntStringFKOneOne.class, new LongIntStringOid(OFFSET_B + 3));
LongIntStringFKOneOne b4 = em.find(LongIntStringFKOneOne.class, new LongIntStringOid(OFFSET_B + 4));
a3.setLongIntStringFKOneOne(b4);
b4.setLongIntStringPKOneOne(a3);
a4.setLongIntStringFKOneOne(b3);
b3.setLongIntStringPKOneOne(a4);
errorIfNotEqual("Swapped field b4.longIntStringPKOneOne should be a3",
a3, b4.getLongIntStringPKOneOne());
errorIfNotEqual("Swapped field a3.longIntStringFKOneOne should be b4",
b4, a3.getLongIntStringFKOneOne());
errorIfNotEqual("Swapped field b3.longIntStringPKOneOne should be a4",
a4, b3.getLongIntStringPKOneOne());
errorIfNotEqual("Swapped field a4.longIntStringFKOneOne should be b3",
b3, a4.getLongIntStringFKOneOne());
commit();
em.close();
em = emf.createEntityManager();
begin();
print("Checking swapped references.");
a3 = em.find(LongIntStringPKOneOne.class, new LongIntStringOid(OFFSET_A + 3));
a4 = em.find(LongIntStringPKOneOne.class, new LongIntStringOid(OFFSET_A + 4));
b3 = em.find(LongIntStringFKOneOne.class, new LongIntStringOid(OFFSET_B + 3));
b4 = em.find(LongIntStringFKOneOne.class, new LongIntStringOid(OFFSET_B + 4));
errorIfNotEqual("Swapped field b4.longIntStringPKOneOne should be a3",
a3, b4.getLongIntStringPKOneOne());
errorIfNotEqual("Swapped field a3.longIntStringFKOneOne should be b4",
b4, a3.getLongIntStringFKOneOne());
errorIfNotEqual("Swapped field b3.longIntStringPKOneOne should be a4",