use of org.datanucleus.samples.rdbms.application.ConflictUser in project tests by datanucleus.
the class SchemaTest method testDuplicateColumnNamesInSimpleAssociations.
/**
* Test conflicts in naming between columns.
*/
public void testDuplicateColumnNamesInSimpleAssociations() {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
// Test conflicts in column naming in ConflictUser class.
// 2 columns have been given the same name and should error
boolean success = false;
try {
tx.begin();
ConflictRole conflictRole = new ConflictRole();
conflictRole.setRole("rolename");
ConflictUser conflictUser = new ConflictUser();
conflictUser.setUser("fred");
conflictUser.setRole(conflictRole);
conflictUser.setRoleid("blabla");
pm.makePersistent(conflictUser);
tx.commit();
} catch (JDOFatalInternalException jdoex) {
if (tx.isActive()) {
tx.rollback();
}
success = true;
}
if (!success) {
fail("completed an unexpected persistence of an object.");
}
// Test conflicts in column naming in ConflictAssociation class.
// A column has been given the same name as the one JPOX will assign
// to a different column
success = false;
try {
tx.begin();
ConflictRole conflictRole = new ConflictRole();
conflictRole.setRole("rolename");
ConflictAssociation conflictAssociation = new ConflictAssociation();
conflictAssociation.setAssociation("assoc1");
conflictAssociation.setRole(conflictRole);
conflictAssociation.setRoleid("blabla");
pm.makePersistent(conflictAssociation);
tx.commit();
fail("completed an unexpected persistence of an object");
} catch (JDOFatalInternalException jdoex) {
if (tx.isActive()) {
tx.rollback();
}
success = true;
}
} catch (Exception e) {
LOG.error("Exception thrown", e);
fail(e.toString());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
Aggregations