-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: SessionFactory closed and events for Seam app
PostPosted: Fri Jun 26, 2009 6:25 pm 
How can my Seam app know when the Hibernate SessionFactory is closed in the org.hibernate.impl.SessionFactoryImpl class? I am using JPA 1.0 (EntityManager interface) with Hibernate as my persistence provider in a Seam 2.0.2 app. I want to perform an operation when the SessionFactory/EntityManagerFactory is closed. How can I implement this? In the Hibernate doc it references events and interceptors but not sure how to hook this up with Seam app and use @Observer method.

The motivation for this question is here: https://www.hibernate.org/216.html. thx.

Code:
/**
    * Closes the session factory, releasing all held resources.
    *
    * <ol>
    * <li>cleans up used cache regions and "stops" the cache provider.
    * <li>close the JDBC connection
    * <li>remove the JNDI binding
    * </ol>
    *
    * Note: Be aware that the sessionfactory instance still can
    * be a "heavy" object memory wise after close() has been called.  Thus
    * it is important to not keep referencing the instance to let the garbage
    * collector release the memory.
    */
   public void close() throws HibernateException {

      if ( isClosed ) {
         log.trace( "already closed" );
         return;
      }

      log.info("closing");

      isClosed = true;

      Iterator iter = entityPersisters.values().iterator();
      while ( iter.hasNext() ) {
         EntityPersister p = (EntityPersister) iter.next();
         if ( p.hasCache() ) {
            p.getCacheAccessStrategy().getRegion().destroy();
         }
      }

      iter = collectionPersisters.values().iterator();
      while ( iter.hasNext() ) {
         CollectionPersister p = (CollectionPersister) iter.next();
         if ( p.hasCache() ) {
            p.getCacheAccessStrategy().getRegion().destroy();
         }
      }

      if ( settings.isQueryCacheEnabled() )  {
         queryCache.destroy();

         iter = queryCaches.values().iterator();
         while ( iter.hasNext() ) {
            QueryCache cache = (QueryCache) iter.next();
            cache.destroy();
         }
         updateTimestampsCache.destroy();
      }

      settings.getRegionFactory().stop();

      if ( settings.isAutoDropSchema() ) {
         schemaExport.drop( false, true );
      }

      try {
         settings.getConnectionProvider().close();
      }
      finally {
         SessionFactoryObjectFactory.removeInstance(uuid, name, properties);
      }

      observer.sessionFactoryClosed( this );
      eventListeners.destroyListeners();
   }


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.