@Override
  @OverridingMethodsMustInvokeSuper
  protected void onDestroy (@Nonnull final IScope aScopeInDestruction) throws Exception
  {
    // Destroy factory
    if (m_aFactory != null)
    {
      if (m_aFactory.isOpen ())
      {
        // Clear cache
        try
        {
          m_aFactory.getCache ().evictAll ();
        }
        catch (final PersistenceException ex)
        {
          // May happen if now database connection is available
        }
        // Close
        m_aFactory.close ();
      }
      m_aFactory = null;
    }
    LOGGER.info ("Closed EntityManagerFactory for persistence unit '" + m_sPersistenceUnitName + "'");
  }
@ Override @ OverridingMethodsMustInvokeSuper protected void onDestroy ( @ Nonnull final IScope aScopeInDestruction ) throws Exception { if ( m_aFactory != null ) { if ( m_aFactory . isOpen ( ) ) { try { m_aFactory . getCache ( ) . evictAll ( ) ; } catch ( final PersistenceException ex ) { } m_aFactory . close ( ) ; } m_aFactory = null ; } LOGGER . info ( "Closed EntityManagerFactory for persistence unit '" + m_sPersistenceUnitName + "'" ) ; }
Called when the global scope is destroyed (e.g. upon servlet context
shutdown)

@throws Exception
if closing fails