I'm a newbie at J2EE, and refactoring an existing Hibernate/Tomcat/Struts app, and I'd like to know the best method for obtaining a session within a Stateless Session Bean. Currently, I'm doing it as outlined in the Wiki:
Context ctx = new InitialContext();
SessionFactory factory = (SessionFactory) ctx.lookup("java:/hibernate/HibernateFactory");
sess = factory.openSession();
Which is working fine, but is this the preferred way to do it in production environments? How expensive is the JNDI lookup for this? Is it possible (or worthwhile) to cache the SessionFactory reference somewhere so I don't have to do the lookup each time? What's the best practice for this?
Thanks!
|