This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Other Application Frameworks and the fly likes Hibernate SessionFactory is initialized/read with every EJB call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Hibernate SessionFactory is initialized/read with every EJB call" Watch "Hibernate SessionFactory is initialized/read with every EJB call" New topic
Author

Hibernate SessionFactory is initialized/read with every EJB call

Urso Wieske
Greenhorn

Joined: Jun 21, 2002
Posts: 2
Hi

I am working with Spring a couple of weeks now.
We are using Spring framework in a standard J2EE application (Hibernate / EJB / Struts).


I have observed that my Hibernate sessionfactory is repeatedly created/instantiated when my EJBs are accessed (for the first time).
As I have understood from the spring documentation, every EJB has it's own instance of the Spring application context.
My first conclusion is : if I have 7 EJB stateless session beans in my EJB container, I have also 7 initializations of sessionfactory.

That is, 7 times hibernate mapping initialization ...

My question is:
"I would want to have only one instance (=one initialization) of sessionfactory which is global for all EJBs AND I do NOT want to use JNDI registration of my Hibernate sessionfactory as MBean(JMX) (Hibernate in Action).?"

Mind you: we are using an older version of BEA Weblogic which has possible no support for JMX / MBeans.


Ideas? Because I am kind of dazzled about the way Spring contexts are implemented with respect to the scope of spring beans.

ThanX
Urso Wieske


U.G.R. Wieske<br />Amsterdam, Netherlands
Jagmohan Negi
Greenhorn

Joined: Aug 24, 2005
Posts: 27
Use singleton pattern for that
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate SessionFactory is initialized/read with every EJB call