@Override
  public void run(RunNotifier notifier) {
    if (isTestScopedSessionFactoryRequired()) {
      testScopedSessionFactory = buildSessionFactory();
      injectSessionFactory(null, testScopedFactoryFields, testScopedSessionFactory);
    }

    try {
      super.run(notifier);
    } finally {
      if (testScopedSessionFactory != null) {
        cleanUpPendingTransactionIfRequired();
        TestHelper.dropSchemaAndDatabase(testScopedSessionFactory);
        testScopedSessionFactory.close();
      }
    }
  }
 public static void dropSchemaAndDatabase(Session session) {
   if (session != null) {
     dropSchemaAndDatabase(session.getSessionFactory());
   }
 }
 public static void dropSchemaAndDatabase(EntityManagerFactory emf) {
   dropSchemaAndDatabase(((HibernateEntityManagerFactory) emf).getSessionFactory());
 }
 @After
 public void tearDown() {
   dropSchemaAndDatabase(emf);
   em.close();
   emf.close();
 }