From f3e45e5e5419fbdbf5f67ab49b97faf418f25b22 Mon Sep 17 00:00:00 2001 From: Donald Woods Date: Wed, 13 Oct 2010 15:56:51 +0000 Subject: [PATCH] additional error handling when clear(EMF) is called git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1022157 13f79535-47bb-0310-9956-ffa450edef68 --- .../test/AbstractPersistenceTestCase.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java index cf2271688..7e326081e 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/AbstractPersistenceTestCase.java @@ -313,17 +313,25 @@ public abstract class AbstractPersistenceTestCase extends TestCase { return; } EntityManager em = emf.createEntityManager(); - em.getTransaction().begin(); - for (ClassMetaData meta : types) { - if (!meta.isMapped() || meta.isEmbeddedOnly() - || Modifier.isAbstract(meta.getDescribedType().getModifiers()) - && !isBaseManagedInterface(meta, types)) { - continue; + try { + em.getTransaction().begin(); + for (ClassMetaData meta : types) { + if (!meta.isMapped() || meta.isEmbeddedOnly() + || Modifier.isAbstract(meta.getDescribedType().getModifiers()) + && !isBaseManagedInterface(meta, types)) { + continue; + } + em.createQuery("DELETE FROM " + meta.getTypeAlias() + " o").executeUpdate(); } - em.createQuery("DELETE FROM " + meta.getTypeAlias() + " o").executeUpdate(); + em.getTransaction().commit(); + } catch (Exception e) { + // ignore + } finally { + if (em.getTransaction().isActive()) { + em.getTransaction().rollback(); + } + em.close(); } - em.getTransaction().commit(); - em.close(); } /**