4 Replies Latest reply on Jun 6, 2006 3:04 PM by Boerre Brox

    Jboss 4.0.4 not closing SessionFactory? Redeploy fails

    Boerre Brox Newbie

      Is anybody else having problems with redeploying on 4.0.4?
      My application works fine on 4.0.3, but fails miserably on 4.0.4GA. I've traced down the problem to having something to do with not closing the sessionfactory. So it's propably either a problem with the undeploy process or cglib?

        • 1. Re: Jboss 4.0.4 not closing SessionFactory? Redeploy fails
          Boerre Brox Newbie

          Oh, and this is the error I get when I try to build a sessionfactory after I've redeployed:

          org.hibernate.cache.CacheException: Attempt to restart an already started EhCacheProvider. Use sessionFactory.close() between repeated calls to buildSessionFactory. Consider using net.sf.ehcache.hibernate.SingletonEhCacheProvider. Error from ehcache was: Cannot parseConfiguration CacheManager. Attempt to create a new instance of CacheManager using the diskStorePath "/tmp" which is already used by an existing CacheManager. The source of the configuration was classpath.
          


          • 2. Re: Jboss 4.0.4 not closing SessionFactory? Redeploy fails
            Boerre Brox Newbie

            Please, isn't there anyone who can help with this?

            It's seriously annoying to have to restart the jboss server every time you redeploy your application.

            I've looked for a soloution for over a week now, but the problem still persists.


            some more info:
            This is how i use the sessionfactory:

            package session;
            
            
            import org.hibernate.HibernateException;
            import org.hibernate.Session;
            import org.hibernate.SessionFactory;
            import org.hibernate.cfg.Configuration;
            /**
             * Configures and provides access to Hibernate sessions, tied to the
             * current thread of execution. Follows the Thread Local Session
             */
            public class HibernateSessionFactory {
            
             /** Holds a single instance of Session */
             private static final ThreadLocal threadLocal = new ThreadLocal();
            
             /** The single instance of hibernate configuration */
             private static final Configuration cfg = new Configuration();
            
             /** The single instance of hibernate SessionFactory */
             private static SessionFactory sessionFactory;
            
             /**
             * Returns the ThreadLocal Session instance. Lazy initialize
             * the <code>SessionFactory</code> if needed.
             *
             * @return Session
             * @throws HibernateException
             */
             @SuppressWarnings("unchecked")
             public static Session currentSession() throws HibernateException {
             Session session = (Session) threadLocal.get();
            
             if (session == null) {
             if(sessionFactory == null) {
             try {
             sessionFactory = cfg.configure().buildSessionFactory();
             }
             catch (Exception e) {
             System.err.println("%%%% Error building SessionFactory%%%%");
             e.printStackTrace();
             }
             }
             try {
             session = sessionFactory.openSession();
             threadLocal.set(session);
             }
             catch (Exception e) {
             System.err.println("%%%% Error opening SessionFactory%%%%");
             e.printStackTrace();
             }
            
             }
            
             /*if(!session.isConnected()) {
             session.reconnect();
             }*/
             return session;
             }
            
             /**
             * Close the single hibernate session instance.
             *
             * @throws HibernateException
             */
             public static void closeSession() throws HibernateException {
             Session session = (Session) threadLocal.get();
             threadLocal.set(null);
             //System.out.println("Closing the session in sessionfactory");
             if (session != null) {
             session.close();
             }
             }
            
             /**
             * Default constructor.
             */
             private HibernateSessionFactory() {
             }
            
            }
            


            and this is my hibernate config:
            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE hibernate-configuration PUBLIC
             "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
             "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
            <hibernate-configuration>
             <session-factory>
             <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
             <property name="hibernate.connection.password">123456</property>
             <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/TRIM</property>
             <property name="hibernate.connection.username">admin</property>
             <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
            
             <!-- mapping files -->
            
             <mapping resource="hibernate_xml/Users.hbm.xml" />
             <mapping resource="hibernate_xml/Module.hbm.xml" />
             <mapping resource="hibernate_xml/ModuleAccess.hbm.xml" />
             <mapping resource="hibernate_xml/UserGroup.hbm.xml" />
             <mapping resource="hibernate_xml/SystemDefault.hbm.xml" />
             <mapping resource="hibernate_xml/RelationType.hbm.xml" />
             <mapping resource="hibernate_xml/Relation.hbm.xml" />
             <mapping resource="hibernate_xml/Resource.hbm.xml" />
             <mapping resource="hibernate_xml/Contact.hbm.xml" />
             <mapping resource="hibernate_xml/ResourceType.hbm.xml" />
             <mapping resource="hibernate_xml/Unit.hbm.xml" />
             <mapping resource="hibernate_xml/ResourceCategory.hbm.xml" />
             <mapping resource="hibernate_xml/Activity.hbm.xml" />
             <mapping resource="hibernate_xml/ActivityLine.hbm.xml" />
             <mapping resource="hibernate_xml/ActivityType.hbm.xml" />
             <mapping resource="hibernate_xml/Status.hbm.xml" />
            
             </session-factory>
            </hibernate-configuration>
            


            I'm using jboss 4.0.4GA and eclipse with jbossIDE to deploy/redeploy. I'm also using the latest 1.6GA release of the JbossIDE plugin.


            • 3. Re: Jboss 4.0.4 not closing SessionFactory? Redeploy fails
              Tamir Efron Newbie

              There are some problems/bugs with the jboss 4.0.4, but the ones I found were related to the web console. Actually some major problems were fixed too...

              When I ported my web applications + hibernate to 4.0.4 I had to remove/adjust the version of some .jar files that hibernate use, as 4.0.4 uses newer version. For hot redeployment to work I adjusted the perm memory settings, and update the jboss-tomcat jsf folder content (only if you need jsf)

              hope it helps...

              • 4. Re: Jboss 4.0.4 not closing SessionFactory? Redeploy fails
                Boerre Brox Newbie

                Thanks for your reply.

                I ended up rewriting the sessionfactory to a mbean instead, and configured the postgresql db connection as a datasource in jboss.

                Now jboss handles the sessionFactory instead of the application, and the redeployment works as expected.