use of org.datanucleus.tests.applicationid.ClassWithUniqueField in project tests by datanucleus.
the class ApplicationIdPersistenceTest method testUniqueConstraint.
public void testUniqueConstraint() throws Exception {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
ClassWithUniqueField u1 = new ClassWithUniqueField(1, "First Name", "Value");
pm.makePersistent(u1);
ClassWithUniqueField u2 = new ClassWithUniqueField(2, "Second Name", "Value");
pm.makePersistent(u2);
tx.commit();
fail("Allowed to insert dupd objects when unique constraint exists");
} catch (JDOException e) {
// Expected
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(ClassWithUniqueField.class);
}
}
Aggregations