PDA

View Full Version : SLSB caching hibernateSessionFactory



jim
Nov 14th, 2005, 04:41 PM
Hi,

I was wondering what the best method of caching the hibernateSessionFactory in the business layer is.

I am using SLSB, business pojo (extends AbstractStatelessSessionBean), DAO, Hibernate. Before attempting to introduce a layered architecture, I was storing the hibernateSessionFactory in a static SLSB member variable which renders the state cached - if I understand the SLSB behaviour correctly.

Question is now, can I do the same with the bizpojo interface and declare it as a static variable.

Anyone have any idea what the overhead would be like for a few hundred hits per minute max on a jndi-lookup for the hibernateSessionFactory taking place for every request?

The reason I ask is that I am not sure that the hibernateSessionFactory which is defined in my applicationContext.xml will be cached otherwise.

Any help is much appreciated.

Jim

Andreas Senft
Nov 15th, 2005, 12:49 AM
If you want to share a SessionFactory between multiple SLSBs maybe you could have a look at ContextSingletonBeanFactoryLocator (http://static.springframework.org/spring/docs/1.2.x/reference/beans.html#d0e2525).

Regards,
Andreas

Juergen Mayrbaeurl
Nov 23rd, 2005, 01:22 AM
You should not cache the SessionFactory, because it's a singleton. Use the ContextSingletonBeanFactoryLocator with your applicationContext.xml and all of your SLBs will have access to the same instance of the SessionFactory.