Hi Anoop,
YOu can use the JNDI context to get the Hibernate's SessionFactory.
1)
in hibernate-cfg.xml give the jndi name as below
<hibernate-configuration>
<session-factory name="HibernateSessionFactory">
2)
in one of your startup servlet or first class handling the request for
session factory creation (we had a start up servlet) , you can have the
session factory created and made avialable
try {
//Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
3)
//in rest of classes which needs the hibernate session factory can get it
from JNDI
InitialContext ctx = new InitialContext();
SessionFactory sessionFactory = (SessionFactory)
ctx.lookup("HibernateSessionFactory");
session = sessionFactory.openSession(); //.getCurrentSession();
hope that helps
--
View this message in context:
http://www.nabble.com/Hibernate-and-Struts-tp19985981p20016169.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]