// test delete and make an object persistent in the same transaction
public void testDeleteMakePersistent() {
long pIdentifier = 1;
PersistenceManager pm = pmf.getPersistenceManager();
try {
Product p = new Product(pIdentifier);
p.setCost("cost1");
p.setProductName("product1");
//make a product persistent
pm.currentTransaction().begin();
pm.makePersistent(p);
Object pId = pm.getObjectId(p);
Assert.assertNotNull("null object identifier", pId);
pm.currentTransaction().commit();
p = null;
p = (Product) pm.getObjectById(pId, true);
Assert.assertNotNull("null instance returned by getObjectById", p);
Assert.assertEquals("Bad product id", pIdentifier, p.getId());
//delete it
//and recreate a new one with the same id
pm.currentTransaction().begin();
pm.deletePersistent(p);
Product newP = new Product(pIdentifier);
newP.setCost("cost2");
newP.setProductName("product2");
pm.makePersistent(newP);
pm.currentTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());