public class HibernateUtil {
        public static SessionFactory sf = null;
        public void Init(){
                if(sf == null){
                         sf = new 
Configuration().configure().buildSessionFactory();
                }
        }

}

public class StartUpServlet extends HttpServlet {
        public void destroy() {
                super.destroy(); // Just puts "destroy" string in log
                // Put your code here
        }
        public void init() throws ServletException {
                try {
                        InitialContext ctx = new InitialContext();
                        SessionFactory oldsf = 
(SessionFactory)ctx.lookup("hibernateJNDI");
                        HibernateUtil h = new HibernateUtil();
                        h.Init();
                        SessionFactory newsf = h.sf;
                        if(oldsf!=null) ctx.rebind("hibernateJNDI", newsf);
                        else ctx.bind("hibernateJNDI", newsf);
                        
                } catch (NamingException e) {
                        e.printStackTrace();
                }
        }
}

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
        xmlns="http://java.sun.com/xml/ns/javaee"; 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";>
        
        
                <listener-class>sysListener.StartUpListener</listener-class>
        
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

<?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";>

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

        <session-factory>
                org.hibernate.dialect.MySQLDialect
                jta<!-- thread -->
        true
        hibernateJNDI
        java:/moreflurish
        org.hibernate.transaction.JTATransactionFactory 
         org.hibernate.cache.HashtableCacheProvider  
        
        <!--property 
name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property-->
        <!--property 
name="jta.UserTransaction">java:comp/UserTransaction</property-->
                
                <!-- mappings -->
                
                
                

        </session-factory>

</hibernate-configuration>

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4160886#4160886

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4160886
_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to